The Artima Developer Community
Sponsored Link

Java Answers Forum
convert an int to a byte array

1 reply on 1 page. Most recent reply: Mar 25, 2004 10:38 AM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Courtenay

Posts: 23
Nickname: courtz
Registered: Apr, 2003

convert an int to a byte array Posted: Mar 24, 2004 9:54 AM
Reply to this message Reply
Advertisement
My end goal is for it to be transmitted over a network. this is the question posed to us:
We need to be able to send more advanced structures over the network. How can we convert these structures to the byte arrays supported by the networking classes?
How is an int represented in Java? Specifically: How many bytes are used to represent an int? What is the relevance of each byte? How can an int be converted into a byte array?
Write a method to convert an int into a byte array.
Write a method that converts the byte array back into an int.
Write a method that returns the size of the byte array needed to store an int.


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: convert an int to a byte array Posted: Mar 25, 2004 10:38 AM
Reply to this message Reply
Free Electronic Book: Thinking in Java, 3rd Edition:
http://www.mindview.net/Books/TIJ/

Flat View: This topic has 1 reply on 1 page
Topic: Windows Menu Bar Previous Topic   Next Topic Topic: Using Java Microedition Classes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use