zoukankan      html  css  js  c++  java
  • JAVA byte有无符号数的转换

    如果你只需要对英文文本的每个字节进行数据处理,则无需考虑有符号数和无符号数的转换问题;

    但如果你需要对含有中文的文本进行字节处理,则可能需要考虑有无符号数的转换问题。

    以下代码均为Java代码。

    1、有符号byte 无符号int:

    byte b= -120;
    int a= bytes & 0xff;
    

    2、无符号int 有符号byte:

    int a= 300;
    byte b= (byte)a;
    

    3、BigInteger 转 有符号byte

    BigInteger b= new BigInteger('300');
    byte bytes= b.byteValue();
    

    就是那么简单~~~

  • 相关阅读:
    2-7
    2-6
    2-5
    2-4
    2-3
    2-1
    2-2
    1-1
    5-7
    第六章例6-1
  • 原文地址:https://www.cnblogs.com/samsenyang/p/5903273.html
Copyright © 2011-2022 走看看