Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

display 1's and 0's of byte array

Thread view: 
dan.ference@gmail.com - 02 Dec 2005 19:07 GMT
I am reading binary messages off of a port via UDP packets ->
socket.receive(packet)

I store the received packet into a byte array -> byte[] received =
packet.getData();

I want to output in binary format the variable received.  How do I get
the 1's and 0's to display instead of the asii characters?  Any help is
greatly appreciated!
Chris Smith - 02 Dec 2005 19:12 GMT
> I am reading binary messages off of a port via UDP packets ->
> socket.receive(packet)
[quoted text clipped - 5 lines]
> the 1's and 0's to display instead of the asii characters?  Any help is
> greatly appreciated!

Integer.toString(data, 2), for anything that fits in an int.  Not that
if you're treating the byte as unsigned, you should instead do
Integer.toString(data & 0xff, 2) to correct for sign extension.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

fastman42 - 02 Dec 2005 19:24 GMT
The solution Integer.toString(int, int) does not work in my case.  The
binary messages are being stored in the variable 'received' which is of
type byte[].  I want to be able to display the 1's and 0's of
'received' to the screen for human readability (not the ascii
characters).  Sorry if i was not clear earlier.
Roedy Green - 02 Dec 2005 20:03 GMT
>The solution Integer.toString(int, int) does not work in my case.  The
>binary messages are being stored in the variable 'received' which is of
>type byte[].  I want to be able to display the 1's and 0's of
>'received' to the screen for human readability (not the ascii
>characters).  Sorry if i was not clear earlier.

use it once on each byte.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Chris Uppal - 02 Dec 2005 20:07 GMT
> The solution Integer.toString(int, int) does not work in my case.  The
> binary messages are being stored in the variable 'received' which is of
> type byte[].

So use a loop ?

   -- chris
Roedy Green - 02 Dec 2005 20:02 GMT
>I want to output in binary format the variable received.  How do I get
>the 1's and 0's to display instead of the asii characters?  Any help is
>greatly appreciated!
see http://mindprod.com/jgloss/binary.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

fastman42 - 02 Dec 2005 20:11 GMT
Thanks for the help... I got it to work!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.