http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

TheGrumpyProgrammer



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

binary conversion



Hey Lionel,

I've included a short program that I wrote that converts a decimal number to 
binary, octal or hexadecimal.  I hope it helps you with an algorithm that 
works.

-Brian


>Hi,
>
>I'm sorry, my brain seems to be getting a bit rusty. I've been working all 
>day trying to write a simple program to convert a binary number into 
>decimal. I tried inputting the number with 'cin', multiplying each digit by 
>128, 64, 32, 16, 8, 4, 2, 1, respectively, and then outputting it with 
>'cout', but every time I get another number than if I convert it by hand. 
>Now I know my conversion (by hand) may be incorrect, but I don't think that 
>00000001 should be equal to 0. Another problem is that my code is pretty 
>long. Can somebody please give me a short formula for doing this 
>translation, in either C, C++, Fortran 77 or Linux Assembler? Another 
>language would also do fine if you tell me where to get a compiler and some 
>tutorials on how to use it. :-) I also have Chipmunk Basic, but I know how 
>limited Basic is.
>
>Also, if somebody could give me a formula for translating from decimal to 
>binary, I would be grateful. I know this is much more trickier, and I have 
>no idea how to use either powers or square roots in C++. If somebody would 
>tell me this, it would also help.
>
>Kind regards,
>
>Lionel Pinkhard
>=================================================================
>The GameProgrammer.Com mailing list is for the open discussion
>of any topic related to the art, science, and business of
>programming games. This list is especially tolerant of beginners.
>We were all beginners once
>
>To SUBSCRIBE or UNSUBSCRIBE please visit:
>http://gameprogrammer.com/mailinglist.html

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

convert.cpp