Android中int,short,long和byte的转换
import
java.nio.ByteOrder;
public
class
BytesTransUtils {
private
String TAG =
"BytesTransUtils"
;
private
static
BytesTransUtils instance =
null
;
private
BytesTransUtils() {
//
Log.i(TAG, "instance BytesTransUtils");
}
public
static
BytesTransUtils getInstance() {
if
(instance ==
null
)
{
instance
=
new
BytesTransUtils();
}
return
instance;
}
public
boolean
testCPU() {
if
(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
//
System.out.println("is big ending");
return
true
;
}
else
{
//
System.out.println("is little ending");
return
false
;
}
}
public
byte
[]
getBytes(
short
s,
boolean
bBigEnding) {
byte
[]
buf =
new
byte
[
2
];
if
(bBigEnding){
for
(
int
i = buf.length -
1
;
i >=
0
;
i--) {
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
copyright © 2008-2019 亿联网络 版权所有 备案号:粤ICP备14031511号-2