Thread View: borland.public.jbuilder.java.language
3 messages
3 total messages
Started by Peter Goldman
Mon, 06 Jun 2005 20:22
Converting to binary representation
Author: Peter Goldman
Date: Mon, 06 Jun 2005 20:22
Date: Mon, 06 Jun 2005 20:22
14 lines
1399 bytes
1399 bytes
I'm working on a java program which takes a byte value and shows binary representation. I know that using Integer.toString(iVal, iRadix) can convert integer value to binary string representation. My problem is, if a value is negative, Integer.toString shows -111111 value instead real binary representation. For example: 122 value in binary is: 01111010. -122 value in binary is 10000110. Using Integer.toString method, -122 is -1111010. I need a way to show -122 in binary 10000110. I don't know if java class library provides additional resources to perform this task. I appreciate some help. Best Regards.
Re: Converting to binary representation
Author: Shankar Unni
Date: Tue, 07 Jun 2005 21:43
Date: Tue, 07 Jun 2005 21:43
11 lines
1330 bytes
1330 bytes
Peter Goldman wrote: > For example: 122 value in binary is: 01111010. > -122 value in binary is 10000110. > Using Integer.toString method, -122 is -1111010. To get an "unsigned byte" representation, just do "byteval & 0xff". byte b = ...; String s = Integer.toString((b & 0xff), 2);
Re: Converting to binary representation
Author: Paul Nichols (TeamB)
Date: Wed, 08 Jun 2005 04:00
Date: Wed, 08 Jun 2005 04:00
11 lines
1295 bytes
1295 bytes
"Peter Goldman" <no@no.no> wrote in message news:42a4b083$1@newsgroups.borland.com... > > I'm working on a java program which takes a byte value and shows binary representation. > I do not know if this library will help or not, but you might want to take a look at it: http://javadoc.zerobandwidth.net/net/zerobandwidth/lang/Binary.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads