• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read/Write ints using 2bytes

 
Lora Tully
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I was wondering if anyone can help me read and write one interger using two bytes. I have an interger between 500-800 that I need to write. Normally I would use...

OUT.writeByte(int)

But as 500 is above one byte (256) I was wondering how to write this, and then later read it back.
As since one int would be spread over two bytes, I have no idea how to read it, normally I would use

IN.readByte()

And I have no idea how to do this. Can anyone help me please?
 
Mike Gershman
Ranch Hand
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try DataOutputStream.writeShort() and DataInputStream.readShort()
 
Lora Tully
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that works great!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic