Results 1 to 5 of 5
  1. #1
    tOpach is offline Member
    Join Date
    Sep 2008
    Location
    Ankara-TURKEY
    Posts
    42
    Rep Power
    0

    Default 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"

    thanks in advance,

    Kind Regards.
    A stitch in time saves nine:D

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    you can pad to the left with zeroes (or 1's for negative numbers)

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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. #4
    emma. is offline Member
    Join Date
    Oct 2009
    Posts
    1
    Rep Power
    0

    Arrow 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. #5
    tOpach is offline Member
    Join Date
    Sep 2008
    Location
    Ankara-TURKEY
    Posts
    42
    Rep Power
    0

    Default

    dear emma.,
    You are vey kind and I forgot to mark it as solved. I mean I have managed to solve it:)
    A stitch in time saves nine:D

Similar Threads

  1. Eclipse- Decimal to binary
    By queen_vee in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 02:17 PM
  2. convert binary to images
    By fiqueudrue in forum New To Java
    Replies: 3
    Last Post: 02-12-2009, 09:16 AM
  3. Convert decimal to binary..pls help..newbie here
    By mephisto772 in forum New To Java
    Replies: 5
    Last Post: 02-12-2009, 08:17 AM
  4. Replies: 7
    Last Post: 01-12-2008, 09:02 PM
  5. Converts a binary number to a decimal
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 09:57 AM

Posting Permissions

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