Denary numbers
systems in binary
Mr.Kemperman
M’Kis - 2021
IB Computer Science
How to store denary numbers?
• As we have learned in our previous lesson, we need to look at how mathematical concepts in the
denary system can be stored in the binary system.
• In math we use 10 characters to represent numbers: 0,1,2,3,4,5,6,7,8,9. After using all the
characters, we ‘reuse’ the characters.
• The computer only uses two characters, 0 and 1. We ‘reuse’ the result.
• Denary contains the prefix “de” which refers to ‘dec’, 10 in Latin.
• Binary contain the prefix ‘bi’, which means 2 in Latin. E.g. Bisexual, bilingual
• The challenge for us becomes: how to store denary numbers in binary? We need to make a mapping
between these two number system!
How to convert to binary……
• Natural numbers = {1,2,3,……}. In CS we call these unsigned integers.
• Integer = whole numbers. Unsigned = only positive (sign is – or +).
• Whole numbers = {…,-2,-1,0,1,2….}. Signed integers in CS.
• Decimals like 3.14, 0.5, -0.25, -0.00001, 3x10-10
• Real numbers like e, sqrt(2) or pi? Irrational numbers?
• What about the operations? 3+4, 0.5x-0.2, 3x4, 0/0?
• What about 10 Modulo 3 = 1? In CS 10 % 3 = 1
Terminology and concepts
• B2D = Binary to Denary conversion.
• Denary uses a base 10, Binary uses base 2. This is the fundamental principal used for conversion.
• Let’s define some terminology first:
• 0111010010111 is called a binary string (=sequence of 0’s and 1’s)
• A bit is one position in a binary string and can either 0 or 1.
• 0101 0010 is a binary string comprised of eight bits and is called a byte.
• A byte is comprised of 2 nibbles (half byte = nibble = 4 bits).
• A binary string has to be read from right to left.
• The right most bit in a binary string is called the Least Significant Bit (LSB)
• The left most bit in a binary string is called the Most Significant Bit (MSB)
Representing values in binary: how many
different values can you store in n bits?
 One bit can represent two values.
 Every bit added double the number of representations.
 How many different values can you store in 3 bits?
 #values = 23
= 8 representations
 E.g. how many denary numbers can you represent in 3
 bits? Well, 8.
 What is the biggest signed integer you can store? 7.
 What is the smallest signed integer you can store? 1.
 Denary 0 = Binary 0 ! If you use three bits:
 010 = 0002
Conversion B2D
• B2D = Binary to Denary (aka Decimal) conversion.
• Straight forward, as we have seen (right).
• If you need to answer the question:
• How many bits do I need to represent 7810 ?
• Well, find a factor of 2 that exceeds 78. Why exceeds?
• 24
= 2x2x2x2 = 16, 78>16, so 4 bits is not enough.
• 26
= 2x2x2x2x2x2 = 64, still too low, so 27
= 128!
• 7 bits needed to represent 78!
Conversion D2B
• D2B = Denary to Binary conversion
• Let’s take 7810 , pronounced ‘denary seventy-eight’. We know we need
7 bits to store this. The computer doesn’t use 7 bits, but the working
unit is byte.
• 7810 = 64 + 8 + 4 + 2, right? Why am I using these numbers? Let’s
rewrite.
• 7810 = 1x64 + 0x32 + 0x16 + 1x8 +1x4 +1x2 + 0x1. Look’s familiar,
doesn’t it.
• All denary numbers can be written as a sum of powers of 2.
• Once you’ve done that, you just copy the 0 and 1’s.
• 10011102 is the binary representation of denary 78.
It’s not that hard, Tweety.
Keep on dividing by two until you
reach 1.
Write 1 if number is odd.
Write 0 if number is even.
1 is the remainder after division.
0 if there is no remainder.
Your answer is binary is shown from
bottom to top!
157 / 2 = 78 rem 1
78 / 2 = 39 rem 0
39 / 2 = 19 rem 1
19 /2 = 9 rem 1
And so on……
Read remainders bottom to top!
.
Let’s apply this flowchart to
45 denary! Dry-run this algorithm!
Get X  X = 45
X > 1? Yes!
Calculate X / 2 and X = 45, so 45 / 2.
Find quotient (Q) and remainder (R). Well:
Q = 22, R = 1, because 22x2 + 1 = 45
Next step:
X becomes 22 (X = quotient = 22)
Y is the result, the binary string.
We add the remainder, which is 1.
Y is printed (means put on the screen).
We follow the flowchart….
X = 22, X>1, Yes!!
Find quotient and remainder…
22 / 2 = 11, Q = 11 and R = 0
………and we following the same ‘loop’
We stop when X=0 or X=1,
because we are done.
Classwork / Homework B2D, D2B conversions
• No calculators allowed this time! Write down all your steps on how you get
the answer.
• Convert the following denary numbers to binary: 55, 134, 64, 1025, 800
• Convert the following binary strings to denary: 10000001, 0001001, 1001,
1111111, 1010101, 01010101.
• Design a flowchart in draw.io for B2D conversion. Input X is a binary string,
Output Y is the denary equivalent.

Number systems in binary. An introduction to number systems in binary.

  • 1.
    Denary numbers systems inbinary Mr.Kemperman M’Kis - 2021 IB Computer Science
  • 2.
    How to storedenary numbers? • As we have learned in our previous lesson, we need to look at how mathematical concepts in the denary system can be stored in the binary system. • In math we use 10 characters to represent numbers: 0,1,2,3,4,5,6,7,8,9. After using all the characters, we ‘reuse’ the characters. • The computer only uses two characters, 0 and 1. We ‘reuse’ the result. • Denary contains the prefix “de” which refers to ‘dec’, 10 in Latin. • Binary contain the prefix ‘bi’, which means 2 in Latin. E.g. Bisexual, bilingual • The challenge for us becomes: how to store denary numbers in binary? We need to make a mapping between these two number system!
  • 3.
    How to convertto binary…… • Natural numbers = {1,2,3,……}. In CS we call these unsigned integers. • Integer = whole numbers. Unsigned = only positive (sign is – or +). • Whole numbers = {…,-2,-1,0,1,2….}. Signed integers in CS. • Decimals like 3.14, 0.5, -0.25, -0.00001, 3x10-10 • Real numbers like e, sqrt(2) or pi? Irrational numbers? • What about the operations? 3+4, 0.5x-0.2, 3x4, 0/0? • What about 10 Modulo 3 = 1? In CS 10 % 3 = 1
  • 4.
    Terminology and concepts •B2D = Binary to Denary conversion. • Denary uses a base 10, Binary uses base 2. This is the fundamental principal used for conversion. • Let’s define some terminology first: • 0111010010111 is called a binary string (=sequence of 0’s and 1’s) • A bit is one position in a binary string and can either 0 or 1. • 0101 0010 is a binary string comprised of eight bits and is called a byte. • A byte is comprised of 2 nibbles (half byte = nibble = 4 bits). • A binary string has to be read from right to left. • The right most bit in a binary string is called the Least Significant Bit (LSB) • The left most bit in a binary string is called the Most Significant Bit (MSB)
  • 5.
    Representing values inbinary: how many different values can you store in n bits?  One bit can represent two values.  Every bit added double the number of representations.  How many different values can you store in 3 bits?  #values = 23 = 8 representations  E.g. how many denary numbers can you represent in 3  bits? Well, 8.  What is the biggest signed integer you can store? 7.  What is the smallest signed integer you can store? 1.  Denary 0 = Binary 0 ! If you use three bits:  010 = 0002
  • 6.
    Conversion B2D • B2D= Binary to Denary (aka Decimal) conversion. • Straight forward, as we have seen (right). • If you need to answer the question: • How many bits do I need to represent 7810 ? • Well, find a factor of 2 that exceeds 78. Why exceeds? • 24 = 2x2x2x2 = 16, 78>16, so 4 bits is not enough. • 26 = 2x2x2x2x2x2 = 64, still too low, so 27 = 128! • 7 bits needed to represent 78!
  • 7.
    Conversion D2B • D2B= Denary to Binary conversion • Let’s take 7810 , pronounced ‘denary seventy-eight’. We know we need 7 bits to store this. The computer doesn’t use 7 bits, but the working unit is byte. • 7810 = 64 + 8 + 4 + 2, right? Why am I using these numbers? Let’s rewrite. • 7810 = 1x64 + 0x32 + 0x16 + 1x8 +1x4 +1x2 + 0x1. Look’s familiar, doesn’t it. • All denary numbers can be written as a sum of powers of 2. • Once you’ve done that, you just copy the 0 and 1’s. • 10011102 is the binary representation of denary 78.
  • 9.
    It’s not thathard, Tweety. Keep on dividing by two until you reach 1. Write 1 if number is odd. Write 0 if number is even. 1 is the remainder after division. 0 if there is no remainder. Your answer is binary is shown from bottom to top! 157 / 2 = 78 rem 1 78 / 2 = 39 rem 0 39 / 2 = 19 rem 1 19 /2 = 9 rem 1 And so on…… Read remainders bottom to top! .
  • 11.
    Let’s apply thisflowchart to 45 denary! Dry-run this algorithm! Get X  X = 45 X > 1? Yes! Calculate X / 2 and X = 45, so 45 / 2. Find quotient (Q) and remainder (R). Well: Q = 22, R = 1, because 22x2 + 1 = 45 Next step: X becomes 22 (X = quotient = 22) Y is the result, the binary string. We add the remainder, which is 1. Y is printed (means put on the screen). We follow the flowchart…. X = 22, X>1, Yes!! Find quotient and remainder… 22 / 2 = 11, Q = 11 and R = 0 ………and we following the same ‘loop’ We stop when X=0 or X=1, because we are done.
  • 12.
    Classwork / HomeworkB2D, D2B conversions • No calculators allowed this time! Write down all your steps on how you get the answer. • Convert the following denary numbers to binary: 55, 134, 64, 1025, 800 • Convert the following binary strings to denary: 10000001, 0001001, 1001, 1111111, 1010101, 01010101. • Design a flowchart in draw.io for B2D conversion. Input X is a binary string, Output Y is the denary equivalent.