当前位置: 技术问答>java相关
如何从byte数组中读出一short?在线给分
来源: 互联网 发布时间:2015-08-24
本文导语: byte a = new byte[10] 若需要读取其中a[3],a[4]两个字节为一个short,怎样写最简单? | a[3]为高八位: short s = (short)a[3] * 256 + a[4]; | int a3 = a[3], a4 = a[4]; short val = (short)...
byte a = new byte[10]
若需要读取其中a[3],a[4]两个字节为一个short,怎样写最简单?
若需要读取其中a[3],a[4]两个字节为一个short,怎样写最简单?
|
a[3]为高八位:
short s = (short)a[3] * 256 + a[4];
short s = (short)a[3] * 256 + a[4];
|
int a3 = a[3], a4 = a[4];
short val = (short) ( (a3
short val = (short) ( (a3