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

1. Member
Join Date
Sep 2008
Location
Ankara-TURKEY
Posts
42
Rep Power
0

## 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.

2. Senior Member
Join Date
Sep 2008
Posts
564
Rep Power
6
you can pad to the left with zeroes (or 1's for negative numbers)

3. 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.

4. Member
Join Date
Oct 2009
Posts
1
Rep Power
0

## 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 :)

5. Member
Join Date
Sep 2008
Location
Ankara-TURKEY
Posts
42
Rep Power
0
dear emma.,
You are vey kind and I forgot to mark it as solved. I mean I have managed to solve it:)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•