如何将int数字或字符串数转换为位数组? [英] How to convert int number or string number in to an bit array?
问题描述
所以我收到了一个字符串ascii TCP上的数字。
所以我从tcp得到52和58。
然后我这样做:
string temp1 = Convert.ToString(Convert.ToChar(buffer1 [0]));
string temp2 = Convert.ToString(Convert.ToChar(buffer1 [1]));
string tempS = temp1 + temp2;
所以temp2不是48,那是对的......
但是现在我需要将数据的位数为48 ..
0011000
添加到数组中。
原因是因为这个数字告诉我有多少设备打开和关闭。
0s关闭,1s开启。
所以如何获得阵列?
还有更好的方式来做我正在做的事情吗?
请参阅以下链接将数字转换为二进制
http://www.programcall.com/7/interview/write-a-program-to-convert-decimal-to-binary-in-csnet.aspx 一>
so I am getting a string ascii number over TCP.
so I get 52 and 58 from tcp.
I then do this:
string temp1 = Convert.ToString(Convert.ToChar(buffer1[0])); string temp2 = Convert.ToString(Convert.ToChar(buffer1[1])); string tempS = temp1 + temp2;
so not temp2 is 48 and that is right ...
but now I need to get the bits for 48..
0011000
into an array.
the reason why is because this number tell me how many devices are on and off.
0s are off and 1s are on.
so how do I get the array ?
also is there a better way to do what I am doing ?
Refer following link to convert number to binary
http://www.programcall.com/7/interview/write-a-program-to-convert-decimal-to-binary-in-csnet.aspx
这篇关于如何将int数字或字符串数转换为位数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!