![]() |
|
#1
|
|||
|
|||
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
|
|||
|
|||
Re: how to make a 'INTEGER to BINARY' code?Quote:
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 GIDBlog
More photos on Flickr by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
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