int32转16位2进制
作者:互联网
byte[] bytes; bytes = BitConverter.GetBytes(Convert.ToInt32(33));//先把33转换为byte数组,长度为4 short s1 = BitConverter.ToInt16(new byte[2] { bytes[0], bytes[1] },0);//前两个byte和后两个byte分别组成short short s2 = BitConverter.ToInt16(new byte[2] { bytes[2], bytes[3] }, 0); string a1 = Convert.ToString(s1, 2).PadLeft(8,'0') ;//先通过Tostring转换为2进制,然后用PadLeft补齐位数 string a2 = Convert.ToString(s2, 2).PadLeft(8, '0'); return a1+a2;
标签:int32,Convert,short,进制,PadLeft,16,bytes,BitConverter,byte 来源: https://www.cnblogs.com/ThisYbc/p/16224071.html