• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

ASCII string to binary conversion

Is there anyone here can help me writing a short C script to prompt the user for a string of 1-5 characters. Each character of the string should be output to an 8 bit binary number?
0
DacTin
Asked:
DacTin
1 Solution
 
AxterCommented:
Hi DacTin,
sounds like homework.

Try doing the work, and when you get stuck, post a specific question.

David Maisonave :-)
Cheers!
0
 
brettmjohnsonCommented:
Keep in mind that a char in C *is* an 8-bit binary number.
0
 
Julian HansenCommented:
I think he means output 'A' as 01000001
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Jaime OlivaresSoftware ArchitectCommented:
You will need some boolean logic:
To know if first bit of a character is on, you can use the and (&) operator:

c = 'A';
if (c&1) {   /* is 1st bit on? */
   /* some action here */
}
0
 
ccworkCommented:
You only have 26 letters. why don't just build an array to store binary pattern for each character? This takes little space (26*9 bytes) tand it is faster than testing each bit.
0
 
ccworkCommented:
And, a char in C is *not* a 8-bit binary number.

The Standard says a char in C *is* a byte. But the size of a byte varies on hardware.
0
 
GladissCommented:
Please have a look at this

ASCII of 'A' = 0100 0001
ASCII of 'B' = 0100 0010
ASCII of 'C' = 0100 0011

Do you mean this ?

Then I have solution

Thanks..........
0
 
ccworkCommented:
If you think a person solves your question, you should accept his answer, assign points and close this question.
0
 
DacTinAuthor Commented:
I myself found the solution. Thanks for your suggestion.

Please close this question.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now