DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   how to convert Binary numbers to decimal numbers and decimal numbers to binary (http://www.daniweb.com/forums/thread174456.html)

jhegie Feb 9th, 2009 2:34 am
how to convert Binary numbers to decimal numbers and decimal numbers to binary
 
How to convert binary numbers to decimal numbers and decimal numbers to binary numbers?


help!!!!!!

Freaky_Chris Feb 9th, 2009 3:48 am
Re: how to convert Binary numbers to decimal numbers and decimal numbers to binary
 
1) Read the rules.
2) Search the forums
3) Show code attempts

GDICommander Feb 9th, 2009 12:34 pm
Re: how to convert Binary numbers to decimal numbers and decimal numbers to binary
 
If you're using an int variable for keeping a decimal value and you want to convert it into a binary value, you should know how an int is represented.

An "int" uses 32 bits for representing the number. You can use binary operators in C++ to get the bytes. (OR / AND). I suggest that you do a search on what they are and how to use them. If you don't know the binary representation, do the same.

It's very easy to print all the bytes of an int. You can use a printf option of write a loop that will iterate 32 times to print every byte of the int.

GDICommander Feb 9th, 2009 12:35 pm
Re: how to convert Binary numbers to decimal numbers and decimal numbers to binary
 
I forgot one thing: you can use >> or << to shift the bits. It can be very useful.


All times are GMT -4. The time now is 5:34 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC