zoukankan      html  css  js  c++  java
  • C# 整数和byte数组互换

       1:          public static byte[] int2Byte(int intValue)
       2:          {
       3:              byte[] b = new byte[4];
       4:              for (int i = 0; i < 4; i++)
       5:              {
       6:                  b[i] = (byte)(intValue >> 8 * (i) & 0xFF);
       7:              }
       8:              return b;
       9:          }
      10:   
      11:          // 将iSource转为长度为iArrayLen的byte数组,字节数组的低位是整型的低字节位
      12:          public static byte[] int2Byte(int iSource, int len)
      13:          {
      14:              byte[] b = new byte[len];
      15:              for (int i = 0; (i < 4) && (i < len); i++)
      16:              {
      17:                  b[i] = (byte)(iSource >> 8 * i & 0xFF);
      18:              }
      19:              return b;
      20:          }
      21:   
      22:          // 将byte数组bRefArr转为一个整数,字节数组的低位是整型的低字节位
      23:          public static int byte2Int(byte[] b)
      24:          {
      25:              int iOutcome = 0;
      26:              byte bLoop;
      27:              for (int i = 0; i < 4; i++)
      28:              {
      29:                  bLoop = b[i];
      30:                  iOutcome += (bLoop & 0xFF) << (8 * i);
      31:              }
      32:              return iOutcome;
      33:          }
    http://www.kissit.com.cn/
  • 相关阅读:
    hadoop安装前的准备
    记录一次Qt5程序无法运行的解决过程
    C#里的Thread.Join与Control.Invoke死锁情况
    qbxt7月笔记
    zhxのDP讲
    有n*m的方格图
    最长上升子序列相关问题笔记
    qbxt游记(清北澡堂划水记
    DAZの七下道法(持续更新
    模板
  • 原文地址:https://www.cnblogs.com/Junelee1211/p/2382246.html
Copyright © 2011-2022 走看看