Serial.print single byte as DEC


I fill a uint8_t with a numeric value between 1 and 250.

How to get the original numeric value ?


uint8_t filledValue;
uint8_t original;

original = filledValue;
filledValue = 35;

// look inn original to see the previous value.

I must be missing what you are asking.

-jim lee

Sorry but I need to explain. I working with LoRa Tx and Rx.

On the sender :

    uint8_t packetNum = 25;
    int sizePacketNum = sizeof(packetNum);
    LoRa.write(packetNum, sizePacketNum);

On receiver:

    uint8_t packetNum;
    while (LoRa.available())
       receivedByte =;
       packetNum = receivedByte;

Here, how to print the original value (25) of packetNum ?

This prints 127 for me. Does it not for you?

void setup()
  uint8_t val = 127;
  Serial.print(val);  // This prints 127
  Serial.println(val);  // This prints 127

  int8_t val2 = 127;
  Serial.print(val2);  // This prints 127
  Serial.println(val2);  // This prints 127

void loop() {}

What DOES it print if not 25?

Is this like Serial.write() where you pass the ADDRESS of the buffer and the number of bytes to send? That would be:
LoRa.write(&packetNum, sizePacketNum);

1 Like

Thanks, you are right. Working fine.

I’m surprised the compiler didn’t warn you that you were trying to use a byte as a pointer. Do you have compiler warnings turned up to “All” in Preferences?

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