• Post Reply Bookmark Topic Watch Topic
  • New Topic

2 bytes converted a Short

 
Andrew Robinson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I convert 2 bytes into a Short object? I have a huge array of bytes that two bytes together have a meaning and I need to get them into a short so I can use it. Anyone know how to do this?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiply and add.
 
Rob Spoor
Sheriff
Posts: 20831
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or shift left and use a bitwise OR.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I said! ;)
 
Henry Wong
author
Sheriff
Posts: 22624
111
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another option is to use ... java.nio.ByteBuffer
 
You don't like waffles? Well, do you like this tiny ad?
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!