I have had a look through the forum and Google but cant find a soulution i understand.
Is there a way i can convert an int to binary of a set length? For example i would like to convert 123 to 00001111011. When i convert the int to binary i get 111011.
rich_330:
I have had a look through the forum and Google but cant find a soulution i understand.
Is there a way i can convert an int to binary of a set length? For example i would like to convert 123 to 00001111011. When i convert the int to binary i get 111011.
How can i add the leading zeros?
are you trying to fill an array with those values or just print them?
look at bitRead() function and see if you can't figure out how to print the leading zeroes in a function that scans the 8 bits in your byte.
rich_330:
At the moment i just want to print them but i would like to fill an array eventullay.
To print them, that's okay. Use the code of BulldogLowell.
To store them in a array, no, don't do that. You have the value. And it's already binary. Putting it into a binairy array after that is just plain useless... Just use bitRead() or a bit shift and you're done.