zoukankan      html  css  js  c++  java
  • 多种数据类型与byte[]字节数组的转换记录

     1 //把其它数字类型:int(32)/long(64)/ushort(16)存入byte[],根据后面的位数偏移,后一位 + 8
    2 int a = 0x911245;
    3 byte[] bys = new byte[4];
    4 bys[0] = (byte)(a);
    5 bys[1] = (byte)(a >> 8);
    6 bys[2] = (byte)(a >> 16);
    7 bys[3] = (byte)(a >> 24);
    8 for (int i = 0; i < bys.Length; i++)
    9 {
    10 Console.WriteLine(bys[i]);
    11 }
    //BitConverter转换
    public static void Main(string[] args)
    {
    int a = 0x911245;
    byte[] bys = BitConverter.GetBytes(a);

    //输出
    for (int i = 0; i < bys.Length; i++)
    {
    Console.WriteLine(bys[i]);
    }
    Console.WriteLine(a.ToString());
    Console.ReadKey();
    }
    //int >> byte[]
    public static byte[] GetBytesInt32(int argument)
    {
    byte[] byteArray = BitConverter.GetBytes(argument);
    return byteArray;
    }
    //byte >> char
    public static char BAToChar(byte[] bytes, int index)
    {
    char value = BitConverter.ToChar(bytes, index);
    return value;
    }
    //byte >> string
    public static string BaToString(byte[] bytes)
    {
    string str = BitConverter.ToString(bytes);
    return str;
    }



  • 相关阅读:
    adb pull / push
    June 25,2014---->Binder(IPC),Dalvik ,DEX/ODEX
    adb 读写模式 挂载文件系统
    INSTALL_FAILED_UID_CHANGED
    Logcat不显示Application的解决办法
    Android终端管理器删除文件夹
    ADB
    StringBuffer
    扑克牌排序
    windows内存管理方式以及优缺点
  • 原文地址:https://www.cnblogs.com/graypigeon/p/2344893.html
Copyright © 2011-2022 走看看