牛骨文教育服务平台(让学习变的简单)
博文笔记

Android中int,short,long和byte的转换

创建时间:2015-12-23 投稿人: 浏览次数:682
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--) {
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。