Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
can java read bits?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Frank, post: 574432"] In terms of reading and storing, binary information is managed by bytes. But, in your example, you're dealing with 16 bits at a time, which is easily managed by a single short primitive. So, you can load this information in as: DataInput input=new DataInputStream( your_input_source ); short encoded=input.readShort(); //just one way to get a short int temp=encoded >>> 12; //highest 4 bits int reading=(encoded & 0x0FF8) >> 3; int therm_name=encoded & 0x0007; which allow you to treat each value by itself as something a bit more natural... recombining: short combine(int temp, int reading, int therm_name) { //only using assert to make sure params are in range assert (temp & 0x000F) == temp; assert (reading & 0x01FF) == reading; assert (therm_name & 0x0007) == therm_name; return (short) ( (temp<<12) | (reading<<3) | therm_name ); } Hope this helps to shed some light on your question! Frank [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
can java read bits?
Top