如何将int数字或字符串数​​转换为位数组? [英] How to convert int number or string number in to an bit array?

查看:92
本文介绍了如何将int数字或字符串数​​转换为位数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我收到了一个字符串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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆