Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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

[Edit] 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
Translated to this
Quote:
I see there are many stupid people who do not realize the purpose, cocky and idiotic gringos
Posted
Updated 29-Jan-13 13:19pm
v4
Comments
Andreas Gieriet 29-Jan-13 18:16pm    
Is it hexadecimal or binary? Your screenshot is confusing.
Andi
Jibesh 29-Jan-13 18:21pm    
you need to explain more about the hex value. what's the logic behind this value and how to operate on this. without much information its just a junk.
Sergey Alexandrovich Kryukov 29-Jan-13 18:34pm    
It is junk, yes, but as it looks like a string of the length 64, it should be a conversion to 64-bit integer value. Andi and I answered, please see.
—SA
Jibesh 29-Jan-13 18:36pm    
but the screenshot op shared reads the letter 'A' on the screen so I doubt its not a simple conversion i guess
Sergey Alexandrovich Kryukov 29-Jan-13 18:46pm    
I see. Well, just one more step, big deal... I don't know why 64-bit then, apparently, it can be interpreted as 8x8 bits, so, 8 byte. But of course, OP needs bitmaps (whatever it is), not stupid strings of '0' and '1', which is just a totally pointless intermediate representation, absolutely redundant.
Pretty bad question, for sure.
—SA

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.
C#
string s = "000000000111000100010010001001111100100010010001001000100000000";
long v = Convert.ToIn64(s, 2);

Cheers
Andi
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jan-13 18:33pm    
Of course, it will work, a 5, but it does not teach OP bit operations, which should be the real purpose of this exercise (what else, right?)
So, my answer suggests to do exactly that. Please see.
—SA
Andreas Gieriet 29-Jan-13 19:42pm    
Thanks for your 5!
See my comment on your solution.
Andi
PIEBALDconsult 29-Jan-13 18:46pm    
Convert, blech, filth.

Use Int64.TryParse (String, NumberStyles, IFormatProvider, Int64)
Andreas Gieriet 29-Jan-13 19:37pm    
This does not allow for binary string to long.
I do not like the Convert class, but under the given preconditions of my solution (to be checked upfront), I would use it.
Cheers
Andi
Sergey Alexandrovich Kryukov 29-Jan-13 19:10pm    
I guess, we tried too hard.
OP "answer" is "I see there are many stupid people who do not realize the purpose, cocky and idiotic gringos"
Do we need such members? :-)
—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
 
Share this answer
 
v2
Comments
Andreas Gieriet 29-Jan-13 19:42pm    
This is the completest answer.
As it looks like, he wants to have just a "magic" number representing his character patterns. The number itself has no constraints other than storing the bit pattern that can be converted back into bits again (I wonder how he will do that). Let's leave that for his next question ;-)
Cheers
Andi
Sergey Alexandrovich Kryukov 29-Jan-13 19:46pm    
Thank you, Andi.
Next..? From OP? I don't want it to happen... :-)
—SA
Andreas Gieriet 29-Jan-13 19:50pm    
Yeah. Just ignore it, if it happens to appear here somewhere ;-)
Andi
Sergey Alexandrovich Kryukov 29-Jan-13 20:19pm    
Maybe you are right, but I reported it, and in the forum, too. Imagine someone new looks at this. What should such person think about our environment? Questionable issue, of course...
—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
 
Share this answer
 
v2
Comments
PIEBALDconsult 29-Jan-13 18:54pm    
9x7, not 8x8; it saves a bit. :D
Sergey Alexandrovich Kryukov 29-Jan-13 18:58pm    
OK, thank you very much, I'll fix it.
—SA
Sergey Alexandrovich Kryukov 29-Jan-13 19:07pm    
Modified my answer. Thank you again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900