byte和bite之间的转换
来源:互联网 发布:自考网络助学平台 编辑:程序博客网 时间:2024/06/06 19:40
- // 返回无符号的2进制表示 1110011
- String hex = Integer.toBinaryString(115);
- System.out.println(hex);
- // 返回2进制的字符串1110011对应的值 115
- System.out.println(Integer.valueOf("1110011", 2));
- // 16进制值转换成二进制
- System.out.println(Long.parseLong("49", 16));
- System.out.println(Long.parseLong("2F", 16));
- /**
- * Byte转Bit
- */
- public static String byteToBit(byte b) {
- return "" +(byte)((b >> 7) & 0x1) +
- (byte)((b >> 6) & 0x1) +
- (byte)((b >> 5) & 0x1) +
- (byte)((b >> 4) & 0x1) +
- (byte)((b >> 3) & 0x1) +
- (byte)((b >> 2) & 0x1) +
- (byte)((b >> 1) & 0x1) +
- (byte)((b >> 0) & 0x1);
- }
- /**
- * Bit转Byte
- */
- public static byte BitToByte(String byteStr) {
- int re, len;
- if (null == byteStr) {
- return 0;
- }
- len = byteStr.length();
- if (len != 4 && len != 8) {
- return 0;
- }
- if (len == 8) {// 8 bit处理
- if (byteStr.charAt(0) == '0') {// 正数
- re = Integer.parseInt(byteStr, 2);
- } else {// 负数
- re = Integer.parseInt(byteStr, 2) - 256;
- }
- } else {//4 bit处理
- re = Integer.parseInt(byteStr, 2);
- }
- return (byte) re;
- }
0 0
- byte和bite之间的转换
- Image 和byte[]之间的转换
- Stream 和 byte[] 之间的转换
- Stream 和 byte[] 之间的转换
- Stream 和 byte[] 之间的转换
- byte[]和String类型之间的转换
- Stream 和 byte[] 之间的转换
- C# Stream 和 byte[] 之间的转换
- C# Stream 和 byte[] 之间的转换
- C# Stream 和 byte[] 之间的转换
- C# Stream 和 byte[] 之间的转换
- String和byte[]之间的相互转换
- (转)Stream 和 byte[] 之间的转换
- C# Stream 和 byte[] 之间的转换
- C# Stream 和 byte[] 之间的转换
- Stream 和 byte[] 之间的转换
- C# Stream 和 byte[] 之间的转换
- C# Stream 和 byte[] 之间的转换
- 一步一步走进Linux HOOK API(一)
- HTML笔记(下)
- 洛谷 数学问题专题 三国游戏
- java垃圾回收与安卓内存分析
- Android接口回调总结,以及运用到弹窗PopWindow的Demo实现
- byte和bite之间的转换
- 关于hibernate的查询返回类型问题总结
- linux ubuntu安装GPU
- Android Studio中代码模板的使用
- MVP模式重用性的一些思考
- Drools规则引擎(一)-Drools-Language
- 编写who命令
- VS 2013使用DirectShow类操作USB摄像头
- 路