1. ## number system conversion

i need to build a program to convert

• Binary-to-Octal, Octal-to-Binary.
• Decimal to Binary and Hexadecimal.
• Binary, Hexadecimal, Octal to decimal.

i have no heads or tail how to do this.. I'm thinking of doing a switch case for the user to choose which conversion to choose.. but i have no idea how to create the formula for the coversion.. for example, to change octal to binary, i may use remainder(%).. but how can i arrange it from down upwards?

2. Can you do those conversions by hand (pen and paper type thing)?

If so, you should be able to write down each step in your own language, and then write some C code that performs those steps.

Yes, the modulus (%) operator will come in handy.

--
Mats

3. yes.. but for example, changing octal to binary, i'll be dividing the numbers in ocatl with the number 2.. The remainder will be taken as the answer.. But it will be taken from down to up.. If i'm doing on paper, i can see it.. but in c programming how can i ask the program tu read it from bottom to up?

4. Well, you may have to "reverse" the number after you generated it, perhaps, or start storing at the back of the array, perhaps?

Also remember that if you read in a number (as an int, rather than as a string), it is always stored in binary form in the computer, no matter what base it was when you read it in.

--
Mats

5. Originally Posted by matsp
Well, you may have to "reverse" the number after you generated it, perhaps, or start storing at the back of the array, perhaps?

Also remember that if you read in a number (as an int, rather than as a string), it is always stored in binary form in the computer, no matter what base it was when you read it in.

--
Mats
i don't quite understand.. i intended to make the input an integer only.. do you mean that the computer will display a binary no matter what?

6. No, what is displayed is the representation of the number in a given base. Internally, the computer stores and manipulates a binary representation of the number.

7. After using a switch to ask the user what type conversion he wants, you can just input the number using scanf() as hexadecimal, octal, or decimal. Then you can output the number using printf() in the system you want.
Your only problem is that scanf() and printf() can't input/output in binary. But as matsp pointed out, don't forget that the computer stores all data in binary regardless of the method of input. So use that (It shouldn't be that hard)...

EDIT: sounds like you want to do the conversions yourself. First you have to learn how to do it manually (you can search Google for that). Then - like matsp said - write some C code that'll do that. Give it a try and we'll help you out if you can't get it.

8. thanks for all your help.. I'll give it a try..