I have a question regarding how the read function works in Software Serial.

recv reads the bits a receiver picks up into a serial buffer. than read returns a uint8_t. However, when i set read() equal to a variable and print it, it doesn't necessarily always print out a byte. For instance: int x = rx.read(); //if the read is supposed to read 60, x prints 111100 int x = rx.read(); //if the read is supposed to read 226, x prints 11100010

How come the first statement doesn't print 00111100?

Sorry, i realize this might be a very dumb question. I looked into the software serial library, and couldn't identify what I'm missing.

1 Answer 1


For the very same reason that you don't normally write 00000069 instead of just 69. The leading 0's are completely meaningless and can be omitted or included without any change to the value.

  • I understand they can be omitted, but does the variable just do that for me?
    – Jonathan
    Commented Oct 30, 2015 at 3:17
  • No it is the print that does it. An int is 16 bits and that is set in stone.
    – Majenko
    Commented Oct 30, 2015 at 9:10
  • OO that makes sense. So int returns the whole byte, but print discards leading 0s. Gotchya, thanks.
    – Jonathan
    Commented Oct 30, 2015 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.