Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes 2 bytes converted a Short Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2 bytes converted a Short" Watch "2 bytes converted a Short" New topic
Author

2 bytes converted a Short

Andrew Robinson
Greenhorn

Joined: Jan 06, 2010
Posts: 15
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

Joined: Sep 29, 2008
Posts: 12617

Multiply and add.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Or shift left and use a bitwise OR.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's what I said! ;)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18492
    
  40

Another option is to use ... java.nio.ByteBuffer


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 bytes converted a Short
 
Similar Threads
UrlyBird with data file record deletions
Deleted record
reading chars and ints in bytes : confusion
byte converter
Reading float, short from InputStream