GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Nov-2005, 05:08
oozsakarya oozsakarya is offline
New Member
 
Join Date: May 2005
Posts: 26
oozsakarya is on a distinguished road

Decimal to binary conversion


Hello I read a character from the user. For example entry is A and I found 'ts ascii number:65 but I want to find its binary form like:0100 1101. Can you help me...
  #2  
Old 17-Nov-2005, 07:47
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,703
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Decimal to binary conversion


Quote:
Originally Posted by oozsakarya
Hello I read a character from the user. For example entry is A and I found 'ts ascii number:65 but I want to find its binary form like:0100 1101. Can you help me...

Please state the problem precisely:

Your example makes no sense.

The ascii value for the character 'A' is 65 decimal (41 hexadecimal). The bits you show are for 4d hexadecimal (77 decimal).

4d hexadecimal is the ascii value for 'M'

What do you really want the program to do? Be specific.

Before you start to write a program, I recommend that you follow at least these three steps:

1. Describe the input. How is the input obtained? (Keyboard, file, or what?)
Is the program going to act on one input character, or is it going to process more than one character. (And, if it is going to process more than one, how will the program know when to stop?)

2. Describe exactly what the program is going to do with the input character(s). (Convert to decimal digits, convert to hexadecimal digits, convert to binary digits, or what?)

3. Describe exactly what output is going to be generated by the program (print binary digits, or what?)

Regards,

Dave
  #3  
Old 17-Nov-2005, 11:51
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Decimal to binary conversion


You need to understand the difference between character/decimal/hex/binary representation of a single integer/character variable.

Put this into a program that inputs your character and see what comes out:
CPP / C++ / C Code:
printf(" %c  %3d  %02X \n", number, number, number);
How does binary relate to these values?

Then you need to understand bit manipulation. The operators
|
&
<<
>>
Once you understand these operators, you have the background to do the program.

Then we can help you clean up your code.

By the way, did you read the Guidelines? They are important too.
__________________

Age is unimportant -- except in cheese
  #4  
Old 17-Nov-2005, 11:59
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,703
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Decimal to binary conversion


Quote:
Originally Posted by WaltP
You need to understand the difference between character/decimal/hex/binary representation of a single integer/character variable.

Put this into a program that inputs your character and see what comes out:
CPP / C++ / C Code:
printf(" %c  %3d  %02X \n", number, number, number);

We kind of covered that part in a previous thread http://www.gidforums.com/t-7569.html, but since the thread seemed to die a quiet and non-productive death, I guess there's no harm in trying again.

I was just trying to get a clear statement of the problem.

Regards,

Dave
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Conversion: Binary, Decimal, Hexadecimal WaltP C Programming Language 1 10-May-2006 06:49
Roman to decimal to roman SpudNuts C++ Forum 2 16-Feb-2005 19:44
Hex Result giving strange answers. Rosdahale C Programming Language 6 07-Dec-2004 20:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:21.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.