类 ByteUtils

java.lang.Object
com.walker.tcp.util.ByteUtils

public class ByteUtils extends Object
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static String
    bytesToHexString(byte[] src)
    Convert byte[] to hex string.
    static String
    bytesToHexString(byte[] src, int begin, int len)
    Convert byte[] to hex string.
    static String
    bytesToHexString2(byte[] src)
    空格分隔
    static String[]
    bytesToHexStrings(byte[] src)
    Convert byte[] to hex string[].
    static String
    byteToHexString(byte src)
     
    static int
    delH(int val)
    去除int最高位
    static String
    getCommand(byte[] cmdArea)
    返回命令字符串,如:106
    static int
    getHeight4(byte data)
    获取高四位
    static int
    getLow4(byte data)
    获取低四位
    static String
    getMsgCmd(byte[] msg)
    获取接收到的信息中的指令码
    static byte[]
    Convert hex string to byte[] 把字符串转化为字节数组
    static String
    int2HexString(int src)
    将 10进制int 转换为占一个字节的hexString
    static String
    intTo4HexString(int src)
    将10进制int转换为占4个字节的hexString
    static byte[]
    intToBytes(int num)
    int -> byte[4] 低位在前
    static String
    intToHexString(int src)
    将10进制int转换为占2个字节的hexString(低字节在前)
    static String
    intToHexStringH(int src)
    将10进制int转换为占2个字节的hexString(高字节在前)
    static String
    itoj(String str, int i, int j)
    将i进制字符串转换成j进制字符串
    static void
    main(String[] args)
     
    static String
    toBinary(byte b)
    2进制
    static byte[]
    toByteArray(int iSource, int iArrayLen)
    int -> byte[iArrayLen]
    static byte[]
    toBytes(int v)
    int -> byte[2]
    static byte[]
    toBytesH(int v)
    int -> byte[2]
    static double
    toDouble(byte[] res, int begainIdx)
    低位在前 的 byte[2] 转 int, int*0.01转成double并保留两位小数
    static String
    toHexString(byte[] byteArray)
    字节数组转成16进制表示格式的字符串
    static String
    将10进制String 转换为占2个字节的hexString(低位在前)
    static int
    toInt2(byte[] res)
    byte[] 转 int
    static int
    toInt2(byte[] res, int begainIdx)
    低位在前 的 byte[2] 转 int
    static int
    toInt3(byte[] bs, int begain)
    低位在前 ,3位的byte[] 转 int
    static int
    toInt4(byte[] bs)
    低位在前 ,4位的byte 转 int
    static int
    toInt4(byte[] bs, int pos)
    将低位在前 ,4位的byte 转 int
    static int
    toIntByH(byte[] bs, int start)
    获取 高位在前的4位byte int值

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • ByteUtils

      public ByteUtils()
  • 方法详细资料

    • toBinary

      public static String toBinary(byte b)
      2进制
      参数:
      b -
      返回:
    • getHeight4

      public static int getHeight4(byte data)
      获取高四位
      参数:
      data -
      返回:
    • getLow4

      public static int getLow4(byte data)
      获取低四位
      参数:
      data -
      返回:
    • delH

      public static int delH(int val)
      去除int最高位
      参数:
      val -
      返回:
    • byteToHexString

      public static String byteToHexString(byte src)
    • bytesToHexString

      public static String bytesToHexString(byte[] src, int begin, int len)
      Convert byte[] to hex string. 把字节数组转化为字符串
      参数:
      src -
      begin - byte[] 起始位置
      len - 长度
      返回:
    • bytesToHexString

      public static String bytesToHexString(byte[] src)
      Convert byte[] to hex string. 把字节数组转化为字符串
      参数:
      src - byte[]
      返回:
      hex string
    • bytesToHexString2

      public static String bytesToHexString2(byte[] src)
      空格分隔
      参数:
      src -
      返回:
    • toHexString

      public static String toHexString(byte[] byteArray)
      字节数组转成16进制表示格式的字符串
      参数:
      byteArray - 需要转换的字节数组
      返回:
      16进制表示格式的字符串
    • bytesToHexStrings

      public static String[] bytesToHexStrings(byte[] src)
      Convert byte[] to hex string[]. 把字节数组转化为字符串数组
    • hexStringToBytes

      public static byte[] hexStringToBytes(String hexString)
      Convert hex string to byte[] 把字符串转化为字节数组
      参数:
      hexString - the hex string, 两位string一个byte, 允许有空格分隔
      返回:
      byte[]
    • int2HexString

      public static String int2HexString(int src)
      将 10进制int 转换为占一个字节的hexString
      参数:
      src -
      返回:
    • intToHexString

      public static String intToHexString(int src)
      将10进制int转换为占2个字节的hexString(低字节在前)
      参数:
      src -
      返回:
    • intToHexStringH

      public static String intToHexStringH(int src)
      将10进制int转换为占2个字节的hexString(高字节在前)
      参数:
      src -
      返回:
    • toHexString

      public static String toHexString(String src)
      将10进制String 转换为占2个字节的hexString(低位在前)
      参数:
      src -
      返回:
    • intTo4HexString

      public static String intTo4HexString(int src)
      将10进制int转换为占4个字节的hexString
      参数:
      src -
      返回:
    • toByteArray

      public static byte[] toByteArray(int iSource, int iArrayLen)
      int -> byte[iArrayLen]
      参数:
      iSource -
      iArrayLen - invalid input: '<'=4
      返回:
    • toBytes

      public static byte[] toBytes(int v)
      int -> byte[2]
      返回:
      低位在前
    • toBytesH

      public static byte[] toBytesH(int v)
      int -> byte[2]
      返回:
      高位在前
    • intToBytes

      public static byte[] intToBytes(int num)
      int -> byte[4] 低位在前
      参数:
      num -
      返回:
    • toInt3

      public static int toInt3(byte[] bs, int begain)
      低位在前 ,3位的byte[] 转 int
      返回:
    • toInt4

      public static int toInt4(byte[] bs)
      低位在前 ,4位的byte 转 int
      参数:
      bs - 低位在前 byte数组
      返回:
    • toIntByH

      public static int toIntByH(byte[] bs, int start)
      获取 高位在前的4位byte int值
      参数:
      bs - 高位在前 byte数组
      返回:
    • toInt4

      public static int toInt4(byte[] bs, int pos)
      将低位在前 ,4位的byte 转 int
      参数:
      bs - byte数组
      pos - 起始位置
      返回:
    • toDouble

      public static double toDouble(byte[] res, int begainIdx)
      低位在前 的 byte[2] 转 int, int*0.01转成double并保留两位小数
      参数:
      res -
      begainIdx - 起始位置
      返回:
    • toInt2

      public static int toInt2(byte[] res, int begainIdx)
      低位在前 的 byte[2] 转 int
      参数:
      res -
      begainIdx - 起始位置
      返回:
    • toInt2

      public static int toInt2(byte[] res)
      byte[] 转 int
      参数:
      res - 低位在前 ,2位的byte数组
      返回:
    • getMsgCmd

      public static String getMsgCmd(byte[] msg)
      获取接收到的信息中的指令码
      参数:
      msg - 接收到的信息
      返回:
    • getCommand

      public static String getCommand(byte[] cmdArea)
      返回命令字符串,如:106
      参数:
      cmdArea -
      返回:
    • itoj

      public static String itoj(String str, int i, int j)
      将i进制字符串转换成j进制字符串
      参数:
      str -
      i -
      j -
    • main

      public static void main(String[] args)