WEEK 3 - Number System
WEEK 3 - Number System
2 Binary
Numbers in binary form are in base 2. This means that the only legal digits are 0 and
1. We need to write the subscript 2 to indicate that the number is a binary number.
Here are examples of numbers written in binary form:
11111102
10112
3 Octal
Numbers in octal form are in base 8. This means that the only legal digits are 0-7.
We need to write the subscript 8 to indicate that the number is an octal number. Here
are examples of numbers written in octal form:
1768
138
4 Hexadecimal
Numbers in hexadecimal form are in base 16. This means that the only legal digits
are 0-9 and the letters A-F (or a-f, lowercase or uppercase does not matter). We
need to write the subscript 16 to indicate that the number is a hexadecimal
number. Here are examples of numbers written in hexadecimal form:
7E16
B16
5 Conversions
5.1 Decimal to Binary / Binary to Decimal
To convert a decimal number to binary, continuously divide the number by 2 and get
the remainder (which is either 0 or 1), and get that number as a digit of the binary
form of the number. Get the quotient and divide that number again by 2 and repeat
the whole process until the quotient reaches 0 or 1. We then get all the remainders
starting from the last remainder, and the result is the binary form of the number.
NOTE: For the last digit which is already less than the divisor (which is 2) just copy the
value to the remainder portion.
For Example:
12610 = ? 2
So, writing the remainders from the bottom up, we get the binary number 11111102
To convert a binary number to decimal, we multiply the binary digit to "2 raised to the
position of the binary number". We then add all the products to get the resulting
decimal number.
For Example:
11111102 = ?10
So, writing the remainders from the bottom up, we get the hexadecimal number
7E1
Converting octal or hexadecimal numbers is also the same as converting binary
numbers to decimal. To do that, we will just replace the base number 2 with 8 for Octal
and 16 for hexadecimal.
For Example (Octal):
1768 = ?10
5.3 Binary to Octal / Octal to Binary
To convert from binary numbers to octal, we partition the binary number into
groups of 3 digits (from right to left), and pad it with zeros if the number of digits is not
divisible by 3. We then convert each partition into its corresponding octal digit. The
following is a table showing the binary representation of each octal digit.
5.4 Binary to Hexadecimal / Hexadecimal to Binary
To convert from binary numbers to hexadecimal, we partition the binary number into
groups of 4 digits (from right to left), and pad it with zeros if the number of digits is not
divisible by 4. We then convert each partition into its corresponding hexadecimal digit.
The following is a table showing the binary representation of each hexadecimal digit.
1.7 Exercises
1.7.1 Writing Algorithms
Given the following set of tasks, create an algorithm to accomplish the following tasks.
You may write your algorithms using pseudocodes or you can use flowcharts.
1. Baking Cake
2. Logging into your laboratory's computer
3. Buying in Grocery in today’s situation . (2020)
Number Conversions
Convert the following numbers:
1. 198010 to binary, hexadecimal and octal
2. 10010011012 to decimal, hexadecimal and octal
3. 768 to binary, hexadecimal and decimal
4. 43F16 to binary, decimal and octal