GIDForums  

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

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Oct-2005, 10:08
justaHSstudent justaHSstudent is offline
New Member
 
Join Date: Oct 2005
Posts: 1
justaHSstudent is on a distinguished road

how to make a 'INTEGER to BINARY' code?


hello.

It's my first time here. Im Ann, a high school kid. Im still learning C++, so can you help me? can you help in in making a "integer to binary" code? I am only allowed to use the 'if statements, while, do-while,for-while, and the loops.' I know how to convert integer to binary, but i am having difficulties in making of code.... thanks for the help.
  #2  
Old 02-Oct-2005, 14:22
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,693
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: how to make a 'INTEGER to BINARY' code?


Quote:
Originally Posted by justaHSstudent
hello.

It's my first time here. Im Ann, a high school kid. Im still learning C++, so can you help me? can you help in in making a "integer to binary" code? I am only allowed to use the 'if statements, while, do-while,for-while, and the loops.' I know how to convert integer to binary, but i am having difficulties in making of code.... thanks for the help.
Congratulations! I think I was in the 14th grade before I really got down and dirty with binary numbers.

The good news is that you don't have to convert integers to binary! They are already stored in the computer as binary numbers. End of assignment.

Oh, you mean that you have to print out the values of the individual bits? Well C++ routines for printing integer values can give you decimal values (or hexadecimal values) but no standard library routine gives you the binary bits.

So, somehow we have to get the integer value of each bit and feed it to an output routine.

Bottom line: you don't have to convert decimal to binary; you have to extract the binary digits that are already in the machine.

Now I can think of at least two ways to use simple arithmetic to extract binary digits from a decimal number: division and subtraction. (I am assuming positive integers only.) There may be more.

Looking at the problem from the computer's point of view: the bits are already in the computer, is there a way to get them out one at a time. The answer is "yes", and it's easy, using a couple of logic (not arithmetic) operations that are part of the C (and, therefore C++) language.

So, since you already know how to do the conversion, maybe you can give a description of the first couple of steps, and we can see if it is practical to make a computer program to do the trick (with if statements and loops and some other good stuff).

This might seem to be kind of hard, and, in many cases it is. But if you can spell it out a little for someone else, lots of times it helps you when you go through the code figuring out why it doesn't work. (That's a joke; of course it will work.)

Regards,

Dave
 
 

Recent GIDBlogMore photos on Flickr 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
Guidelines for posting requests for help - UPDATED! WaltP C++ Forum 1 22-Aug-2008 00:07
c++ source code to make a program that asks a username and password.. curious_one C++ Forum 2 06-Sep-2005 10:53
Problem with int mixed with char,... leitz C++ Forum 17 07-Dec-2004 20:56
converting binary to integer... tru504187211 C++ Forum 3 10-Feb-2004 07:11

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

All times are GMT -6. The time now is 00:58.


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