954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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!!!!!!

jhegie
Newbie Poster
3 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

1) Read the rules.
2) Search the forums
3) Show code attempts

Freaky_Chris
Master Poster
702 posts since Apr 2008
Reputation Points: 325
Solved Threads: 118
 

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
Posting Whiz in Training
211 posts since Jun 2008
Reputation Points: 72
Solved Threads: 26
 

I forgot one thing: you can use >> or << to shift the bits. It can be very useful.

GDICommander
Posting Whiz in Training
211 posts since Jun 2008
Reputation Points: 72
Solved Threads: 26
 
aplantia
Newbie Poster
1 post since Feb 2010
Reputation Points: 4
Solved Threads: 0
 

There is also the Windows calculator who can do decimal-to-binary and binary-to-decimal transformations. It might be useful if you want to validate what you do in code.

GDICommander
Posting Whiz in Training
211 posts since Jun 2008
Reputation Points: 72
Solved Threads: 26
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You