Computing.Net > Forums > Programming > How to convert Ascii to binary

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to convert Ascii to binary

Reply to Message Icon

Name: Paul
Date: February 21, 2002 at 17:49:00 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: Wanderer
Date: February 22, 2002 at 06:32:54 Pacific
Reply:

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.


0

Response Number 2
Name: Kenneth
Date: February 22, 2002 at 07:13:31 Pacific
Reply:

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.


0

Response Number 3
Name: mari
Date: May 7, 2002 at 13:37:05 Pacific
Reply:

I need help, but I guess this is more simple.

I have these two lines:
'FIRST' '2' 'C'
1 2 3

They 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?



0

Response Number 4
Name: Naavi
Date: May 20, 2002 at 23:08:53 Pacific
Reply:

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


0

Response Number 5
Name: chel
Date: June 6, 2002 at 15:35:45 Pacific
Reply:

http://www.theskull.com/javascript/ascii-binary.html


0

Related Posts

See More



Response Number 6
Name: pereyra
Date: July 10, 2002 at 23:54:27 Pacific
Reply:

How to convert ascii to binary
for example:
û
ý
¢
¥
¨
«
¯
²
µ
¸
º
½
 
¢
¥
§
©
ª
¢
»
³
¬
¦
ÿ
ú
ô
ï
ê
å
á
ü
ø
ù
þ
ã
ç
ë
ï
ó
÷
û
ÿ
£
¦
ª
¬
¯
²
µ
¸
»
¾
¡
£
¥
¨
ª


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: How to convert Ascii to binary

Converting ASCII to HEX www.computing.net/answers/programming/converting-ascii-to-hex/14918.html

How to convert string to a binary www.computing.net/answers/programming/how-to-convert-string-to-a-binary/839.html

how to convert chars to int www.computing.net/answers/programming/how-to-convert-chars-to-int/11828.html