Computer Programming in C++
(IT 112)
Chapter I: Number Systems
MINERVA M. FIESTA
2025
Page |1
Table of Contents
Introduction to Bases ...................................................................................................................2
Lesson 1: Binary ......................................................................................................................2
Binary in Computing .............................................................................................................3
Hexadecimal ............................................................................................................................4
Value of a Digit .........................................................................................................................4
Summary..................................................................................................................................5
Units of Measure in Computing ................................................................................................5
Octal Number System ..............................................................................................................6
Representation of Octal Number ..........................................................................................6
Page |2
Introduction to Bases
We use number bases daily without noticing. Normally, we use decimal (base 10) since each
digit has ten possible values, likely due to humans having ten fingers. However, other bases
exist. For instance, in the movie Avatar, the Na'vi use base 8 because they have eight fingers.
In computing, binary (base 2) and hexadecimal (base 16) are commonly used. To indicate non-
decimal bases, we use prefixes like 0b for binary (e.g., 0b1100111101 equals 829 in decimal).
While any base is possible, binary, hexadecimal, and decimal are most common in computers.
• Binary (Base 2): leading 0b
• Decimal (Base 10): leading nothing (we use it all the time!)
• Hexadecimal (Base 16): leading 0x
Lesson 1: Binary
There are only 10 types of people in the world, those that understand binary and
those that don’t.
Binary numbers are expressed as a combination of 0s and 1s. For example, 100110 is the binary
equivalent of the number 38.
For Example:
Common examples of binary data include:
• Machine Code (001010101100111001010010011)
• Boolean Expressions (True or False)
• Hardware states (On or Off)
• Networking and File Storage
The word binary comes from "Bi-" meaning two. We see "bi-" in words such as "bicycle" (two
wheels) or "binocular" (two eyes). When you say a binary number, pronounce each digit
(example, the binary number "101" is spoken as "one zero one", or sometimes "one-oh-one").
This way people don't get confused with the decimal number. A single binary digit (like "0" or
"1") is called a "bit". For example 11010 is five bits long. The word bit is made up from the words
"binary digit"
Example: What is 11112 in Decimal?
Page |3
• The "1" on the left is in the "2×2×2" position, so that means 1×2×2×2 (=8)
• The next "1" is in the "2×2" position, so that means 1×2×2 (=4)
• The next "1" is in the "2" position, so that means 1×2 (=2)
• The last "1" is in the ones position, so that means 1
• Answer: 1111 = 8+4+2+1 = 15 in Decimal
Example: What is 10012 in Decimal?
• The "1" on the left is in the "2×2×2" position, so that means 1×2×2×2 (=8)
• The "0" is in the "2×2" position, so that means 0×2×2 (=0)
• The next "0" is in the "2" position, so that means 0×2 (=0)
• The last "1" is in the ones position, so that means 1
• Answer: 1001 = 8+0+0+1 = 9 in Decimal Example:
What is 1.12 in Decimal?
• The "1" on the left side iaas in the ones position, so that means 1.
• The 1 on the right side is in the "halves" position, so that means 1×(1/2)
• So, 1.1 is "1 and 1 half" = 1.5 in Decimal Example: What is 10.112 in Decimal? • The "1"
is in the "2" position, so that means 1×2 (=2)
• The "0" is in the ones position, so that means 0
• The "1" on the right of the point is in the "halves" position, so that means 1×(1/2)
• The last "1" on the right side is in the "quarters" position, so that means 1×(1/4)
• So, 10.11 is 2+0+1/2+1/4 = 2.75 in Decimal
Binary in Computing
You may find yourself asking why we go through all the bother of binary numbers when the
decimal system has worked so well for humans for so long.
Binary data, when run through hardware, is seen as power applied or power not applied. An
incredible level of precision and regulation would have to be built into the hardware to modify
the applied electrical voltage so minutely as to vary between ten levels of power.
Specially-designated binary numbers also represent various alphabets, including ASCII and
Unicode. ASCII is an older system for representing characters, and Unicode is the current
international standard for characters.
Binary data also typically comes in specific lengths, for example, eight bits is called a Byte and
two Bytes (16 bits) is called a Word. When the incoming data follows these guidelines, it is easy
for the hardware to process and compute the desired result.
Page |4
File storage on your computer is referenced in Byte size. For example, your favorite app might
be 250 MegaBytes (MB).
Hexadecimal
Hexadecimal (base 16), often called “hex,” is a convenient and concise way to represent binary
numbers on a computer. Hex numbers are often used for values like colors and any other place
where we need to represent bits more space efficiently. They are also commonly used to
represent memory addresses.
Every four binary digits become a single hexadecimal digit, which simplifies conversions
between the two bases. Because hexadecimal is base 16, we must have 16 numerals, including
zero.
Decimal Hexadecimal
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A
11 B
12 C
13 D
14 E
15 F
Notice the use of the letters A, B, C, D, E, and F, which means “15” (F) is the largest numeral in
any column.
Let’s look at one hex digit to four binary digits:
0xA9FC = 0b1010100111111100
Let’s expand that so we can see the results more easily:
0x A 9 F C = 0b 1010 1001 1111 1100
Value of a Digit
When we see a number in a base other than 10, we might find it difficult to understand the
actual value of that number. In this section, we’ll go over converting a non-decimal number to a
decimal value.
The value of a digit is determined by its placement in a number. Its decimal value is determined
when we take the digit value and multiply it by the base value to the power of the exponent
value. The exponent value begins at 0 for the rightmost digit. The exponent value increases by
1 each time we move one digit to the left.
Take the decimal number 123. Note that decimal values have a base of 10.
Page |5
1⋅102+2⋅101+3⋅1001⋅102+2⋅101+3⋅100
• The rightmost digit is 3. To determine this digit’s decimal value, we must multiply 3 by
base value 10 to the power of 0 (100) which equals 3.
• The next value will be the digit to the left. In our example, 2 will be the next digit. To find
this digit’s decimal value, we will use the same formula as before, but this time we will
increase the exponent value by 1. So the decimal value of the second digit is 2 times
101 which equals 20.
• Continuing on, the next digit to the left is 1. We will once again increase the exponent
value by 1 to find its value. Its decimal value is 1 multiplied by 102 which equals 100.
When we add the decimal value of each digit together, we get 100 + 20 + 3 which equals our
value 123.
This seems simple with a decimal number, but we can apply this logic when determining the
value of a number in other bases too. We can find the decimal value of binary number 101 like
so:
• The rightmost value is 1 - its decimal value is determined by multiplying 1 with the value
2 to the power of 0 (20) which is 1. We use 2 here since that’s the base of binary values
like 10 is the base of decimal values.
• The value of the next digit to the left is 0. We’ll increase the exponent value by 1. Its
decimal value is 0 multiplied by 21 which equals 0.
• The value of the next digit to the left is 1. We’ll increase the exponent value by 1 again.
Its decimal value is 1 multiplied by 22 which equals 4.
We’ll add each of the digit’s decimal values together to find the decimal value of the binary
number 101. 4 + 0 + 1 = 5. So binary value 101 is equivalent to decimal value 5.
Summary
• Binary numbers are expressed in base 2, meaning they are represented using only the
values 1 and 0. Binary data can be found in computing in areas such as machine code
and boolean expressions.
• Hexadecimal numbers are expressed in base 16. They are represented using a
combination of decimal numbers 0-9 as well as letters A-F. Hexadecimal numbers can
be found in memory addresses as well as colors.
Units of Measure in Computing
Computers are digital. This means that they operate on numbers, be it photos, music, or text
documents; everything within a computer is represented as a number, and all operations are
some form of arithmetic.
Data representation and storage
It all starts with a bit (the binary digit), which makes up the smallest unit of data for computers.
Being a binary value, this unit can only have one of two values: 0 or 1, usually to represent if an
electronic signal is on or off.
Page |6
All data on the computer is represented in this binary notation. For example, the
number 228 can be represented as 11100100 in binary, and a lowercase j can be represented
as 01101010 in the ASCII encoding standard. These groupings of 8 bits are so common that it
has a special name, a byte.
Bytes serve as the more common unit that a person may come across, usually with unit prefixes
to represent more workable amounts of data:
Value Name (Abbreviation) Example
1000 Bytes Kilobyte (kB) A typical email (~2kB)
10002 Bytes Megabyte (MB) A novel (~1.5MB) or 1 song (~5MB)
10003 Bytes Gigabyte (GB) A 1080p movie (5GB)
10004 Bytes Terabyte (TB) Entire major libraries
10005 Bytes Petabyte (PB) All the data held by a major tech
company
Octal Number System
Octal Number System is one the type of Number Representation techniques, in which
there value of base is 8. That means there are only 8 symbols or possible digit values, there are
0, 1, 2, 3, 4, 5, 6, 7. It requires only 3 bits to represent value of any digit. Octal numbers are
indicated by the addition of either an 0o prefix or an 8 suffix. Position of every digit has a weight
which is a power of 8. Each position in the Octal system is 8 times more significant than the
previous position, that means numeric value of an octal number is determined by multiplying
each digit of the number by the value of the position in which the digit appears and then adding
the products. So, it is also a positional (or weighted) number system. Octal number system uses
numbers from 0 to 7. Let us take an example, to understand the concept. As we said, any
number with base 8 is an octal number like 248, 1098, 558, etc. Like Octal number is
represented with base 8, in the same way, a binary number is represented with base 2, decimal
number with base 10 and the hexadecimal number is represented with base 16. Examples for
these number systems are:
• 222 is a binary number
• 10010 is a decimal number
• 4016 is a hexadecimal number
If we solve an octal number, each place is a power of eight.
• 1248= 1 × 82 + 2 × 81 + 4 × 80
Representation of Octal Number
Each Octal number can be represented using only 3 bits, with each group of bits having a
distich values between 000 (for 0) and 111 (for 7 = 4+2+1). The equivalent binary number of
Octal number are as given below − Octal Digit Value Binary Equivalent 0 000 1 001 2 010 3 011
4 100 5 101 6 110 7 111 Octal number system is similar to Hexadecimal number system. Octal
number system provides convenient way of converting large binary numbers into more compact
and smaller groups, however this octal number system is less popular.
Octal Digit Value Binary Equivalent
0 000
Page |7
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Example-1 − The number 111 is interpreted as
111 = 1x82+5x81+7x80 = 157
Example-2 − A decimal number 21 to represent in Octal representation
(21)10=2x81+1x80=(25)8 So, decimal value 21 is equivalent to 25 in Octal Number System.
Hexadecimals
A Hexadecimal Number is based on the number 16 6 Different Values There are 16
Hexadecimal digits. They are the same as the decimal digits up to 9, but then there are the
letters A, B, C, D, E and F in place of the decimal numbers 10 to 15: Hexadecimal: 0 1 2 3 4 5 6
7 8 9 A B C D E F Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 So a single Hexadecimal digit
can show 16 different values instead of the normal 10.
Page |8
Numbers can be placed to the left or right of the point, to show values greater than one or less
than one:
The number just to the left of the point is a whole number. As we move left, every
number place is 16 times bigger.
The first digit on the right of the point means sixteenths (1/16). As we move further
right, every number place is 16 times smaller (one sixteenth as big). More Examples
Example 1: What is 4B5 (Hexadecimal)?
More Examples Example 1:
What is 4B5 (Hexadecimal)?
• The "4" is in the "16×16" position, so that means 4 ×16×16
• The "B" (11) is in the "16" position, so that means 11 ×16
• The "5" is in the "1" position so that means 5.
o Answer: 4B5 = 4×16×16 + 11×16 + 5 (=1205) in Decimal
Example 2: What is 2.3 (Hexadecimal)?
• On the left side is "2", that is the whole number part.
• The 3 is in the "sixteenths" position, meaning "3 sixteenths", or 3/16
So, 2.3 is "2 and 3 sixteenths" (=2.1875 in Decimal) The Word "Hexadecimal" The word
"Hexadecimal" means "based on 16" (From Greek hexa: "six" and Latin decima: "a tenth part").
Page |9
Number System Conversion Table
How to convert from decimal to hex conversion steps:
1. Divide the number by 16.
2. Get the integer quotient for the next iteration.
3. Get the remainder for the hex digit.
4. Repeat the steps until the quotient is equal to 0.
Decimal to Hex conversion table:
Example #1 Convert 756210 to hex:
Example #2 Convert 3563110 to hex:
P a g e | 10
P a g e | 11
How to convert from Hex to binary: