java.lang.Integer.toHexString(b[n] & 0XFF)中0XFF使用的必要性

byte[] b = {1,2,20,108};

String stmp = java.lang.Integer.toHexString(b[n] & 0XFF)

在32位的电脑中数字都是以32格式存放的,如果是一个byte(8位)类型的数字,他的高24位里面都是随机数字,低8位

才是实际的数据。java.lang.Integer.toHexString() 方法的参数是int(32位)类型,如果输入一个byte(8位)类型的数字,这个

方法会把这个数字的高24为也看作有效位,这就必然导致错误,使用& 0XFF操作,可以把高24位置0以避免这样错误

的发生

0xFF = 1111 1111  低8位为1,高位都为0

故 &0xFF 可将数字的高位都置为0,低8位不变

http://blog.csdn.net/guo_rui22/article/details/2826308

时间: 2024-12-17 16:28:15

java.lang.Integer.toHexString(b[n] & 0XFF)中0XFF使用的必要性的相关文章

MySQL分段统计SQL写法 与 Mybatis 报错:java.math.BigDecimal cannot be cast to java.lang.Integer

mysql> select -> sum(case when score<60 then 1 else 0 end) as '<60', -> sum(case when score>=60 and score<=69 then 1 else 0 end) as '60~69', -> sum(case when score>=70 and score<=79 then 1 else 0 end) as '70~79', -> sum(ca

java.lang.Integer can not be cast to java.lang.Long

hibernate 查询出来的结果 id 是int类型,xml文件配置的是int, 在jython 中调用hibernate 进行查询,字段的类型是java.lang.Long, 直接将id 传进去,报java.lang.Integer can not be cast to java.lang.Long 异常,将 id 进行强转,(Long)id,传进去,正常了. java.lang.Integer can not be cast to java.lang.Long,布布扣,bubuko.com

MyBatis出错Result Maps collection does not contain value for java.lang.Integer

Servlet.service() for servlet [SpringMVC] in context with path [/eyou] threw exception [Request processing failed; nested exception is org.apache.ibatis.builder.IncompleteElementException: Could not find result map java.lang.Integer] with root causej

javax.el.PropertyNotFoundException: Property &#39;id&#39; not found on type java.lang.Integer

javax.el.PropertyNotFoundException: Property 'id' not found on type java.lang.Integer    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)    at jav

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integer (n/a)];

题记:以前记录过一些自己遇到的BUG,这个行为,让我一看报错的提示信息就能定位到问题的所在,后来记得比较多了,好多是重复性的再加上比较忙就没有详细的记录了,今天的工作量比较小,就顺便记录一下,以便以后更快的解决此类问题. BUG的报错信息如下所示: org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integ

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;fundId&#39; in &#39;class java.lang.Integer&#39;

Struts Problem Report Struts has detected an unhandled exception: Messages: There is no getter for property named 'fundId' in 'class java.lang.Integer' nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for prope

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

hibernate查询结果条数集 原写法: Integer count = (Integer )session.createQuery(hql).uniqueResult(); 报错:java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer 原因: 从Hibernate 3.0.x/3.1.x升级到最新的3.2版之后,3.2版的很多sql函数如count(), sum()的唯一返回值已经从In

org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.Defau

出现org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.DefaultLoadEventListener.checkIdClass(DefaultLoadEvent

使用mybatis报错constructor found in com.atguigu.mybatis.bean.Department matching [java.lang.Integer, java.lang.String]

报错constructor found in com.atguigu.mybatis.bean.Department matching [java.lang.Integer, java.lang.String] 构造方法不匹配,因为反射中会使用默认的无参构造器,而当我们一旦写了新的带参构造方法,那么就不会存在无参构造方法了,需要重新写过.自己在相应的实体中写一个无参构造方法就可以了. 完整报错如下所示: org.apache.ibatis.exceptions.PersistenceExcept