This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Convert byte stream to int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Convert byte stream to int" Watch "Convert byte stream to int" New topic

Convert byte stream to int

Ashish Malik
Ranch Hand

Joined: Jul 11, 2010
Posts: 50
Hi, i m tryin to send some integer data over bluetooth.
I am sending it as a byte but want to convert it at reciever end to the original integer that was sent.

The sender code snippet is as follows:

The code for reciever is like this:

Sending and recieving works fine!
Ashish Malik
Ranch Hand

Joined: Jul 11, 2010
Posts: 50
Found the way...
instead of using InputStream and OutputStream...i used
DataInputStream and DataOutputStream...they got methods as...writeInt() and readInt()

But anyways where DataInputStream cannot be used and we have to use InputStream what to do then!
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

You can use a ByteBuffer to read primitives from a byte array.

apigee, a better way to API!
Don't get me started about those stupid light bulbs.
subject: Convert byte stream to int