# how to convert decimal value into 8-bit binary value

• 05-12-2009, 09:17 PM
tOpach
how to convert decimal value into 8-bit binary value
Could anyone tell me how to convert decimal value into 8-bit binary value.

Integer.toBinaryString(int x) gives binary string but it is not 8- bit value. For example it returns as "1000001" for int 65 and what I want is "01000001"

Kind Regards.
• 05-12-2009, 10:56 PM
emceenugget
you can pad to the left with zeroes (or 1's for negative numbers)
• 05-13-2009, 03:54 AM
Eranga
Yes, best way to do this is padding zeros at the beginning.

In this way, if you give a negative number, you may confused with the result. It's 32 bits long. No need to padding 1's at the begging. Just have a try and see.
• 10-26-2009, 10:18 PM
emma.
How do you do this?
Hi I am stuck on trying to pad this binary value, I can concat the binary strings but obviously they are wrong due to the lack of leading zeros, is there a good way of padding the binary, then concatinating the binary strings together?

:) thanks, i'm not a very good programmer you see :)
• 10-26-2009, 11:17 PM
tOpach
dear emma.,
You are vey kind and I forgot to mark it as solved. I mean I have managed to solve it:)