views:

1520

answers:

5

Hi, I am working on a calculator that allows you to perform calculations past the decimal point in octal, hexadecimal, binary, and of course decimal. I am having trouble though finding a way to convert floating point decimal numbers to floating point hexadecimal, octal, binary and vice versa.

The plan is to do all the math in decimal and then convert the result into the appropriate number system. Any help, ideas or examples would be appreciated.

Thanks!

+2  A: 

Hmm... this was a homework assignment in my university's CS "weed-out" course.

The operations for binary are described in Schaum's Outline Series: Essential Computer Mathematics by Seymour Lipschutz. For some reason it is still on my bookshelf 23 years later.

As a hint, convert octal and hex to binary, perform the operations, convert back to binary.

Or you can perform decimal operations and perform the conversions to octal/hex/binary afterward. The process is essentially the same for all positional number systems arithmetic.

Ken Gentle
+1  A: 

What Programming Language are you using? it is definatly a good idea to change everything into binary do the math on the binary then convert back. if you multiply a (unsigneD) binary number by 2, ti is the same as a Bit Shift Left ( << 1 in C), a division by 2 is the same as a Bit shit Right (>> in C). addition and subtraction is the same as you would do in elementary school.

also, remember that if you cast a float as an int it will truncated it int(10.5) = 10;

A: 

Thanks to all for the help!

A: 

I had this same problem a few days ago. I found http://www.binaryconvert.com, which allows you to convert between floating point decimal, binary, octal, and hexadecimal in any order you want.

A: 

The above link doesn't work. It's actually http://www.digitconvert.com ;)