Unity_数据类型之间的相互转换

来源:互联网 发布:sql如何建立级联 编辑:程序博客网 时间:2024/06/06 14:49
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace CodeTest{    class Program    {        static void Main(string[] args)        {            //位bit   0,1 表示二进制文件的基础单位            //字节byte   八个0和1 (对位的封装)            //基本类型float , int (4个字节), string ,ushort            int a = 10;// 10 0 0 0            int b = 255;// 255 0 0 0             int c = 256;// 0 1 0 0             int c1 = 257;//1 1 0 0            int c2 = 265;//10 1 0 0            int d = 256 * 256;//0 0 1 0            ////  int(4字节)(8位) Int32            //int e = 1 * 1 + 1 * 2 + 1 * 4 + 1 * 8 + 1 * 16 + 1 * 32 + 1 * 64 + 1 * 128;            //Console.WriteLine(e);            ////e==b;            //int f = 0 * 1 + 0 * 2 + 0 * 4 + 0 * 8 + 0 * 16 + 0 * 32 + 0 * 64 + 0 * 128 + 1 * 256;            //Console.WriteLine(c);            ////f==c;            //// (BitConverter)将基础数据类型与字节数组相互转换。            //byte[] bytes = BitConverter.GetBytes(c);            //for (int i = 0; i < bytes.Length; i++)            //{            //    Console.WriteLine(bytes[i]);            //}            ////// shotr(2)(8) Int16            //ushort g = 10;// 10 0            //byte[] bytes = BitConverter.GetBytes(g);            //for (int i = 0; i < bytes.Length; i++)            //{            //    Console.WriteLine(bytes[i]);            //}            ////转成不同类型会是不一样的结果;            //int h = 256 * 256 * 256;            //byte[] bytes = new byte[] { 0, 0, 1, 0 };            //short shortA = BitConverter.ToInt16(bytes,0);            //Console.WriteLine(shortA);// 0             //int intA = BitConverter.ToInt32(bytes,0);            //Console.WriteLine(intA);// 65536            //ushort ushortA = BitConverter.ToUInt16(bytes,0);            //Console.WriteLine(ushortA);//0            //uint uintA = BitConverter.ToUInt32(bytes,0);            //Console.WriteLine(uintA);//65536        }    }}
原创粉丝点击