CS114 Lab: Decimal, Binary, Hexadecimal Systems

lake Waban view

Representation of Numbers and the Binary System

Inside a computer, numbers are represented using the Binary System, as you know.

Learn the first 10 powers of 2:

power 2 to the power
(in decimal)
01
12
24
38
416
532
664
7128
8256
9512
101024

Decimal and Binary values from 0 to 15:

Decimal ValueBinary Value
00
11
210
311
4100
5101
6110
7111
81000
91001
101010
111011
121100
131101
141110
151111

Binary to Decimal

You already know how to do this. As a reminder, number 10011 in binary is the same as 19 in decimal, because:

1*16 + 0*8 + 0*4 + 1*2 + 1*1 = 19

Decimal to Binary

To convert a decimal number to the binary equivalanr, we need to express the decimal number as a sum of powers of 2. Based on this, write down an 1 for every power that appears in the sume, and a 0 for each that does not. Pad it up with leading zeros so that you get a whole number of bytes. Here is an example:

113(decimal) = 1*64 + 1*32 + 1*16 + 1*1 = 
1*64 + 1*32 + 1*16 + 0*8 + 0*4 + 0*2 + 1*1 --> 01110001 (binary)