Number Conversions - Fall 2023

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Number

Conversions
Mathematics for Computing – MATH10025
Fall 2023
Sheridan College

Tarek El Salti & Joshua Schneider

School of Applied Computing


Reference
 Rosen, H., K. (2019). Discrete Mathematics
and Its Applications, 8th edition.

School of Applied Computing


Algorithms
 Informal definition: “a sequence of steps
that leads to the desired answer”
 Formal definition: “is a finite sequence of
precise instructions for performing a
computation or for solving a problem.”
 An algorithm is written in terms of
pseudocode.
 Algorithms were named after ABU JA’FAR
MOHAMMED IBN MUSA AL-KHOWARIZMI
School of Applied Computing
Algorithms (continue)
 Examples
 If max < gradeStudent then max :=
gradeStudent
 {x is the largest grade in L} (i.e., comment)
 …..

School of Applied Computing


Converting Between Number Systems
 Incomputer mathematics, you will be
required to convert between the decimal,
binary, and hexadecimal number systems.
 We will also consider systems arbitrary
bases.

School of Applied Computing


Converting Between Number Systems
(continue)
 There are a number of methods we can
employ to convert a decimal number to
another base.
 The algorithm which we will focus on is the
remainder method.

School of Applied Computing


Converting Between Number Systems
(continue) - The Remainder Method
 First step: Divide the decimal number by the base
of the number system you want to convert to.
 Second step: The remainder is the least significant
(last) digit of the conversion.
 Third step: Take the quotient from Step 2 and
divide it by the base of the number system.
 Fourth step: The remainder from Step 3 is the place
value to the left of the converted equivalent.
 Fifth step: Take the quotient from Step 4 and divide
it by the base of the number system.
 Sixth step: Repeat Steps 4 & 5 until the quotient is
zero (0).

School of Applied Computing


Converting Hexadecimal to Binary
 Hexadecimal numbers are useful in
computer mathematics because larger
binary numbers can be represented in
hexadecimal using less symbols.
 To convert a hexadecimal number to
binary, write the four bit binary equivalent
for each hexit.

School of Applied Computing


Converting Hexadecimal to Binary
(continue)

School of Applied Computing


Converting Binary to Hexadecimal
 Here
is the algorithm to convert a binary
number to its hexadecimal equivalent:
 First step: Start with the right-most (least
significant) bit and group into sets of four
bits.
 Second step: If the last group contains less
than four bits, pad to the left with zeros until
the group has four bits.
 Third step: Convert each group of four bits
to its hexadecimal equivalent.
School of Applied Computing
Converting Binary to Hexadecimal
(continue)

School of Applied Computing


Arithmetic Operations –
Addition/Subtraction

School of Applied Computing


Arithmetic Operations –
Addition/Subtraction (continue)

School of Applied Computing


Arithmetic Operations –
Addition/Subtraction (continue)

School of Applied Computing


Arithmetic Operations –
Addition/Subtraction (continue)

School of Applied Computing


Arithmetic Operations –
Addition/Subtraction (continue)

School of Applied Computing


Complement Math
 Unfortunately, computers do not have the
capabilities to subtract binary numbers.
 Complement addition is required to
perform subtraction.

School of Applied Computing


Complement Math (continue)

School of Applied Computing


Complement Math (continue)
 NINES complement = TENS complement – 1
OR
 TENS complement = NINES complement + 1

School of Applied Computing


Complement Math (continue)

School of Applied Computing


Binary Complements
 ONES complement: it can be found easily
by “flipping” or “switching” each bit
 We can use the following algorithm to get
the TWOS complement of a binary
number:
 Get the ONES complement by “flipping”
each bit in the binary number (change all
0’s to 1’s and all 1’s to 0’s).
 Add 1 to the ONES complement.
School of Applied Computing
Binary Complements (continue)

School of Applied Computing


Binary Complements (continue)
 Example: Subtract the following binary
number using the complement method:
0110011 − 0001010
 STEP 1: Find 2’s complement of 0001010
 STEP 1.1: FLIP ALL BITS: 1110101
 STEP 1.2: ADD 1: 1110110
 STEP
2: Add the 2’s complement of
0001010
School of Applied Computing
Binary Complements (continue)

 Drop the left-most bit and the answer is:


0101001

School of Applied Computing

You might also like