OOPortal OOPortal


Data Types  «Prev 

Converting from decimal to binary

The largest power of 2 less than or equal to 204 is 2 raised to the 7th = 128. Thus the binary number should have a 1 in the position corresponding to 2^7.

Subtracting 128 from 204 gives 76. The largest power of 2 less than or equal to 76 is 2 raised to the 6th = 64.
Thus the binary number should have a 1 in the position corresponding to 2^6.

Subtracting 64 from 76 gives 12. The largest power of 2 less than or equal to 12 is 2 raised to the 3 = 8.
Thus the binary number should have a 1 in the position corresponding to 2^3.

Subtracting 8 from 12 gives 4. The largest power of 2 less than or equal to 4 is 2^2 =4. Thus the binary should have a 1 in the position corresponding to 2^2.

Computer Science Structured Approach
Subtracting 4 from 4 givess 0. We are completed.

From our work we see that the binary equivalent of 204 should have 1s in the corresponding to 2^7, 2^6, 2^3 and 2^2. All other positions should contain 0's. Thus the binary equivalent of 204 is 11001100.