如何将这个位串转换为数字? [英] how to convert this string of bits to a number ?

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

问题描述

您好,请问如何将此字符串转换为数字?



字符串为:



000000000111000100010010001001111100100010010001001000100000000



图像为:



https://plus.google.com/ u / 0 / photos / 109784902246866879155 / albums / 5839011728343671265



请勿通过JIBESH [/ EDIT]回答

OP正在尝试和这里的会员一起玩。他发布了这个并自行删除了



Hello, please,how to convert this string to a number ?

the string is :

000000000111000100010010001001111100100010010001001000100000000

the image is this :

https://plus.google.com/u/0/photos/109784902246866879155/albums/5839011728343671265

DO NOT ANSWER BY JIBESH[/EDIT]
OP is trying to Play with members here.He posted this and deleted by self

Quote:

Veo que hay muchas personas estupidas que no se dan cuenta el proposito,gringos engreidos e imbeciles

Veo que hay muchas personas estupidas que no se dan cuenta el proposito , gringos engreidos e imbeciles

翻译成这个

Translated to this

引用:

我看到有很多愚蠢的人没有意识到目的,骄傲和愚蠢的gringos

I see there are many stupid people who do not realize the purpose, cocky and idiotic gringos

推荐答案

如果你确定字符串正好有64个0和1字符,如果你愿意的话将这64位存储为int64(即 long )您可以使用 Convert.ToInt64方法(字符串,Int32) [ ^ ]。

例如
If you are sure that the string has exactly 64 "0" and "1" characters, and if you want to store these 64 bits as int64 (i.e. long) you may use Convert.ToInt64 Method (String, Int32)[^].
E.g.
string s = "000000000111000100010010001001111100100010010001001000100000000";
long v = Convert.ToIn64(s, 2);



干杯

Andi


Cheers
Andi


如果这是一串比特,它已经是一个数字,没有什么可以转换的。我想你在谈论 System.String 由字符0和1组成,每个字符代表一点。但这很简单。



这是提示:使用按位''<<'''运算符。编写代码,看看是否可以实现它。如果你仍然有问题,请问一个问题并告诉我们你在哪里被困。



另一个想法是:将你的64位值分解为8个字节;也就是说,定义8个字节的数组,使用输入字符索引和''<<'''在循环中填充字符串中每个字节的位;最后使用类 System.BitConverter 将字节数组转换为无符号的64位值:

http://msdn.microsoft.com/en-us/library/system.bitconverter.toint64.aspx [ ^ ]。



您还可以使用签名的 System.Int64 。显然,在某些情况下,结果会有所不同:-)



这很简单。试试吧。



祝你好运,

-SA
If this a string of bits, it''s already a number, there is nothing to convert. I think you are talking about System.String composed of characters ''0'' and ''1'' each representing a bit. But this is very simple.

Here is the hint: use the bitwise ''<<'' operator. Write the code and see if you can achieve it. If you still have a problem, ask a question and tell us where are you stuck.

Another idea is: break your 64-bit value into 8 bytes; that is, define array of 8 bytes, fill bits in each byte from your string in a loop using the input character index and ''<<''; and, finally use the class System.BitConverter to convert array of bytes to an unsigned 64-bit value:
http://msdn.microsoft.com/en-us/library/system.bitconverter.toint64.aspx[^].

You can also use signed System.Int64. Apparently, in some cases, the result will be different :-)

This is really simple. Try it.

Good luck,
—SA


[看了这张图片后:]



你根本不需要这个字符串。这是一个毫无意义的中间表示。你真的需要代表一个位图,比如7x9。因为它不适合字节数组,所以保持64位(无符号)整数值是不切实际的,但你仍然可以,因为63< 64 :-)我不认为你应该打扰,因为字形大小可以变化,如果不是现在,那么将来。



你可以使用,例如, System.Drawing.Bitmap ,包含任何可用的编辑器或您自己的编辑器,并以通常的方式将其存储在文件/流中。您可以使用以下方法访问位:

http: //msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx [ ^ ]。



您可以从中提取位位图,没有任何冗余字符串。同样,相同的按位操作,无论如何你都需要知道。



-SA
[After looking at this image:]

You don''t need to have this string at all. This is a pointless intermediate representation. You really need to represent a bitmap, say, 7x9. As it does not fit in a array of bytes, it''s impractical to keep in in a 64-bit (unsigned) integer value, but you still can, because 63 < 64 :-) I don''t think you should bother, because the glyph size can vary, if not now, then in future.

You can use, for example, System.Drawing.Bitmap, with any of the available editors or with one of your own, and store it in a file/stream in a usual way. You can access bit using these methods:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].

You can extract bits from this bitmap, without any redundant strings. Again, same bitwise operations, which you need to know anyway.

—SA


这篇关于如何将这个位串转换为数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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