简体   繁体   中英

2 byte array in Little Endian to int without java.nio.*

I want to convert 2byte array in Little Endian to Int without using java.nio.*. How can I accomplish this?

With regards

这应该是技巧int val = (anArray[1] & 0xff) << 8 + (anArray[0] & 0xff);

Just came across this post and realised that the accepted answer will not work correctly because + has a higher precedence than << .

Therefore it should be int val = ((anArray[1] & 0xff) << 8) + (anArray[0] & 0xff); instead.

you have 2 Byte means 16 bit because in Little indian The least significant 16-bit unit stores the value you can use bitvise operations in java

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM