Reputation: 31
Need a solution on how to perform the following: receive a decimal value, convert it to 32-bit Hex, then separate that 32-bit hex and get high 16-bit and low 16-bit values. I have been digging around net and cannot find much info.
Upvotes: 3
Views: 9266
Reputation: 533590
Not sure why you are converting to hex but to turn a 32-bit value straight into two 16-bit values.
int x = ...
short high = x >> 16;
short low = x & 0xFFFF;
Upvotes: 6
Reputation: 184200
I expect this is a homework problem. Accordingly, I will give you information that can help you solve it rather than a solution.
toHexString()
method.substring()
method along with length()
and some simple subtraction.Upvotes: 4
Reputation: 14964
Some APIs you might find useful: http://download.oracle.com/javase/6/docs/api/java/io/DataInputStream.html http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html#parseInt(java.lang.String, int) http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html#toHexString(int) http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Hex.html
Upvotes: -1