?
Solved

ASCII string to binary conversion

Posted on 2005-03-23
9
Medium Priority
?
323 Views
Last Modified: 2010-04-15
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
Comment
Question by:DacTin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 100 total points
ID: 13615793
Hi DacTin,
sounds like homework.

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

David Maisonave :-)
Cheers!
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 13619107
Keep in mind that a char in C *is* an 8-bit binary number.
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 13619487
I think he means output 'A' as 01000001
0
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.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13624941
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
 
LVL 1

Expert Comment

by:ccwork
ID: 13631725
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
 
LVL 1

Expert Comment

by:ccwork
ID: 13714022
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
 
LVL 1

Expert Comment

by:Gladiss
ID: 13782062
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
 
LVL 1

Expert Comment

by:ccwork
ID: 13789227
If you think a person solves your question, you should accept his answer, assign points and close this question.
0
 

Author Comment

by:DacTin
ID: 13934282
I myself found the solution. Thanks for your suggestion.

Please close this question.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question