Converting binary data from i2c read to a decimal to be read on display

Hi, i'm definitely a beginner with coding and Arduinos so simple explanations and help would greatly be appreciated. I have stored 1 byte that tells me what frequency has been tuned on the radio chip, (there is a conversion from the value received to the FM signal but id rather do that with decimal values). I would like this value to be viewed on an OLED display, I don't think the library I am using has an option to print a byte as DEC. Is there any simple way of displaying the byte as a decimal when the variable is used, as appose to the binary to which it was original set
as?

Wire.requestFrom(radio_Adress,2);
    while(Wire.available())
    {
      byte h = Wire.read();
      byte l = Wire.read();
    }
uint8_t channel = (h<<6) | (l); /* Altough the number of bits required is no more than 8 since the max
channel is 208, there is a 10 bit space to retrieve the channel and the first 2 are in the last 2 bits
of the high byte so I just included those last two anyway */
display.println(channel);

Thank you for reading.

I don't think the library I am using has an option to print a byte as DEC.

How about casting it to an "int"?

Or make 'channel' a integer and use the Arduino word(). I think that some bits have to be removed.

Koepel:
Or make 'channel' a integer and use the Arduino word(). I think that some bits have to be removed.

Thankyou! It worked :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.