Tom's Guide | Tom's Hardware | Tom's Games | PC Safety Suite
![]() |
![]() |
![]() |
Comment:
I have made a program in which i can do CRC-16 check on binary, but I need help
I need a code in C++ that can convert ASCII string to binary. I would appreciate if someone helps me
+1 | ![]() |
What are you talking about?
What kind of binary do you want? Maybe I can help if I know what is a CRC-16 check.
+1 | ![]() |
Although I don't know how a CRC-16 check is done offhand, I can help you with getting an ASCII string converted to binary.
The real secret is that you don't need to convert anything, ASCII strings are already numbers anyways. The binary is right there.
If you're using a char array, like char name[20], then each "char" is really an unsigned byte value. They're just numbers, like an int or a short or a long. Ints can be 16 or 32 bits long, longs are 32 bits long, shorts are 16 bits long, and chars are 8 bits long. 32 bits can hold the values -2.1 billion to 2.1 billion (approx.), 16 bits -32768 through 32767, and 8 bits -128 through 127.
So the binary is already there. Now, if you want to print out the binary, or get a single binary digit out of a number, that's a different story.
To get a binary digit out of a number:
To get the Nth digit (from the right, starting at one) of number X, do:
(X >> (n - 1)) & 0x01
(yes, i know there are other ways of doing this, but i'm making this simple)
Let's say we have the number 10111001 binary, and we want to get the third digit from the right, which is a zero. First, we shift the number right (n - 1) amount of times, or 2 times, giving us 00101110. We then and (&) this with the number 1. This means that every bit except the first, rightmost (least significant) bit will be set to zero, leaving us with two possible values - 0 or 1.
Printing a decimal number in binary is much harder, so I'm only going to explain that if you need it.
+1 | ![]() |
I need help, but I guess this is more simple.
I have these two lines:
'FIRST' '2' 'C'
1 2 3They are in an ascii file. How do I write that to a binary one? I open the binary file as simple as
OPEN (1,FILE='table',FORM='BINARY',STATUS="UNKNOWN")
Do I need to care about the end of the line or something?
+1 | ![]() |
Is there any editor or online demo where I can input ascii charecters and get the binary equivalents?
Required for a class room explanation.
Naavi
+1 | ![]() |
How to convert ascii to binary
for example:
û
ý
¢
¥
¨
«
¯
²
µ
¸
º
½
¢
¥
§
©
ª
¢
»
³
¬
¦
ÿ
ú
ô
ï
ê
å
á
ü
ø
ù
þ
ã
ç
ë
ï
ó
÷
û
ÿ
£
¦
ª
¬
¯
²
µ
¸
»
¾
¡
£
¥
¨
ª
![]() |
Opening Folders with C++
|
How can get text from obj...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.