This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert byte stream to int

 
Ashish Malik
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a ByteBuffer to read primitives from a byte array.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic