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 / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

I need help writing an integer to an output byte stream in Java

Thread view: 
the1bugbear@gmail.com - 04 Mar 2006 22:08 GMT
I have an opcode that I need to write to a file

for instance 47152 = B830.

When I try to write the integer value to a file using an output stream
the it only writes the first byte of the pattern so the file just gets
the 30 and not the B8.  I need to be able to send up to 4 bytes at a
time.  I am allowed to extract the bytes if that is possible one at a
time.  The problem is really that I get either 1,2,3, or 4 bytes at a
time and I can't tell in advance.

Since it is an opcode I have to build it based on the input file.  Any
advice would be great thanks crew.
Roedy Green - 04 Mar 2006 23:55 GMT
>When I try to write the integer value to a file using an output stream
>the it only writes the first byte of the pattern so the file just gets
>the 30 and not the B8.  I need to be able to send up to 4 bytes at a
>time.  I am allowed to extract the bytes if that is possible one at a
>time.  The problem is really that I get either 1,2,3, or 4 bytes at a
>time and I can't tell in advance.

For precise binary, you probably want a DataOutputStream or
LEDataOutputStream so you can send out big or little endian groups of
4-bytes. Plain OutputStreams go a byte at a time.

see http://mindprod.com/applets/converter.html for sample code.
Signature

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



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.