Breaking Sec

Full Version: Binary Conversions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've had to perfect my understanding of how Binary and Decimal numerical systems convert between each other. Doing it on paper as well. I believe many colleges cover it. The concept isn't tooo hard:


1. Decimal to Binary

Binary is based on a remainder system. Take example the number 18:

18
9
4
2
1

Break it down into halves. Divide each by two.

18 /2
9 /2
4 /2
2 /2
1 /2

Detect remainders...

0
1
0
0
1

Inverse...

10010 is the binary equivelant of 18 decimal.

2. Binary to Decimal

This part tends to be more difficult. You have to understand, unlike Decimal being a ten-part system.

Say you're converting 1010 binary to it's decimal form:

First, Inverse. 0101

0*(2^0) then 1*(2^1) then 0*(2^2) and lastly 1*(2^3)

0 + 2 + 0 + 8

Answer: 10

Hope you learn, thank you for reading.
I coded that last part in C++ real fast :P
Code:
#include <iostream>
using namespace std;

int main()
{
cout << "Binary was: 0101\n";
int x = 0*(2*0);
int y = 1*(2*1);
int z = 0*(2*2);
int q = 1*(2*2*2);
int a = x+y+z+q;
cout << "Converted to Dec it is: " << a;
getchar();
}
neat
Way to bring back really old posts. Still a good tut tho.
Reference URL's