byte ---> hex String
public static String byte2HexString(byte[] b){
String ret = "";
for(int i=;i<b.lenght;i++){
String hex = Integer.toHexString(b[i]&0XFF);
if(hex.length()==){
hex = ''+hex;
}
ret+=hex.toUpperCase();
}
return ret;
}
1 1个字节8位 1个BYTE与上2个hex字符
1 个HEX字符4位
2 Integer.toHexString(int ---);
作用 int(十进制有符号) ---> String (十六进制)
3 byte ==>int
byte b;
int i=b&0Xff;
分析 :byte -->8 位 int 32位
byte转int位数不够要补位 补位有偏差 故需要清零多出的高24位 即与上0xFF
补码:
1111 1111
[ 1111 1111 ] [ 1111 1111 ] [ 1111 1111 ] [1111 1111]
0XFFFF FFFF与上0Xff高24位清零
&与 & --> & --> & --> & ---> 两边都成立才可以为真 | -->
| -->
| -->
| -->
两边只有一方成立即可
byte b = 24;
int i = b&FF; 清零高24位
-2
字节 1111 1110 补码
字 1111 1111 1111 1110 补码
字节 1000 0010 源码
字 0000 0000 1000 0010 源码
二进制 十进制
1B byte = 8 bit 1B = 8bit 1B=8bit
1 KB =1024B 1KB= 2^10B 1KB = 10^3B
1MB =1024kb 1MB = 2^20B 1MB=10^6b
1GB = 1024mb 1GB = 2^30B 1GB = 10^9B
1TB = 1024GB 1TB= 2^40B 1TB= 10^12B
1024 2^10 10^3
hex string == byte
1 hex string -- integer Integer i = Integer.parseInt("EA",16);
2 integer -- byte Byte b = i.byteValue();
Byte HexString byte b = -22;
1 byte -->integer Integer i = b.intValue();
2 integer -->string String newII = Integer.toHexString(ii).subString(6,8);
byte ---> hex String的更多相关文章
- byte[] 转Hex String
一.一个字符串转byte数组怎么转? byte[] byteArray = String.getBytes(); 二.又想把生成的数组转回字符串怎么办? String covertString = n ...
- C#中的Byte,String,Int,Hex之间的转换函数。
/// <summary> Convert a string of hex digits (ex: E4 CA B2) to a byte array. </summary> ...
- 图片转为byte[]、String、图片之间的转换
package com.horizon.action; import java.io.ByteArrayOutputStream; import java.io.File; import java.i ...
- C# Byte[] 转String 无损转换
C# Byte[] 转String 无损转换 转载请注明出处 http://www.cnblogs.com/Huerye/ /// <summary> /// string 转成byte[ ...
- BufferHelp byte[] Stream string FileStream Image Bitmap
/******* * *** ***** ** ** * * * * * * * * ***** * * * * * * * * * * * * * * * ******* *** * ***** * ...
- [转]关于网络通信,byte[]和String的转换问题
最近的项目中要使用到把byte[]类型转换成String字符串然后通过网络发送,但发现发现出去的字符串和获取的字符串虽然是一样的,但当用String的getBytes()的方法得到的byte[]跟原来 ...
- 如何在Byte[]和String之间进行转换
源自C#与.NET程序员面试宝典. 如何在Byte[]和String之间进行转换? 比特(b):比特只有0 1,1代表有脉冲,0代表无脉冲.它是计算机物理内存保存的最基本单元. 字节(B):8个比特, ...
- C# byte[]与char[]、string与char[]、byte[] 与 string 互转
1. byte array -> char array Byte[] b=new byte[5]{0x01,0x02,0x03,0x04,0x05}; Char[] c=Encoding.AS ...
- Java - byte[] 和 String互相转换
通过用例学习Java中的byte数组和String互相转换,这种转换可能在很多情况需要,比如IO操作,生成加密hash码等等. 除非觉得必要,否则不要将它们互相转换,他们分别代表了不同的数据,专门服务 ...
随机推荐
- linux之iptables常用命令
iptables详解 iptables -L 该命令会以列表的形式显示出当前使用的 iptables 规则,每一条规则前面的编号可以用来做为其它操作--例如删除操作--的参数,很有用 iptables ...
- PHP 抽象类、接口,traint详解
PHP底层实现(http://blog.jobbole.com/94475/) 一,抽象类:abstract abstract class HeHe{ public $age=18;//可以定义属性 ...
- 自己没有记住的一点小知识(ORM查询相关)
一.多对多的正反向查询 class Class(models.Model): name = models.CharField(max_length=32,verbose_name="班级名& ...
- linux下安装mysql-5.6.41
1.下载安装包,下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads .选择完版本,然后点击下方 No thanks, just ...
- Web前端渗透测试技术小结(一)
首先端正一下态度不可干违法的事 1.SQL注入测试 对于存在SQL注入的网页,使用SQL语句进行关联查询(仿照C/S模式)eg http://www.foo.com/user.php?id=1 常 ...
- Nginx详解二十五:Nginx架构篇之Nginx常见的问题
Nginx常见的问题 1.相同server_name多个虚拟主机优先级访问,是按读取文件的优先级来排序 在/opt/app/下准备3个code文件夹,下面放入3个html文件,里面的内容分别是code ...
- oracle数据库无法连接 The Network Adapter could not establish
Caused by: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection 这个错误 ...
- Django的Session存储Redis环境配置
第一步:在项目目录下的settings.py中MIDDLEWARE中加上中间件: # session中间件Django项目默认启用Session 'django.contrib.sessions.mi ...
- 【第一部分】10Leetcode刷题
一.删除链表的倒数第N个节点 题目:19. Remove Nth Node From End of List 分析:典型的利用双指针法解题.首先让指针first指向头节点,然后让其向后移动n步,接着让 ...
- es6 箭头函数【箭头表达式】
箭头函数,通过 => 语法实现的函数简写形式,C#/JAVA8/CoffeeScript 中都有类似语法.与函数不同,箭头函数与其执行下文环境共享同一个 this.如果一个箭头函数出现在一个函数 ...