Computers don't count in denary like we do. They are made a switches and don't have any fingers. They count in Base 2 or Binary. Part of being a computer scientists is being able to count in different number bases than the one that we normally count in. We are learning ...- About different number bases
So that we can ...- Describe the format of number systems
- The concept of a number base - Writing numbers to include their base, n_{B} - Describe and use the denary number system
- Describe and use the binary number system
- Discuss the concept of binary coding
- Represent unsigned denary numbers in binary format and vice versa
- Describe and use the hexadecimal number system
- Perform base conversions.
We use our fingers to count like a scale with
10 different levels (technically 11 if we start at zero but early civilisations didn't have a concept of zero).This is why we use the Base
10 or Denary number system. However, if we use all 10 of our fingers, we are actually representing 1 lot of 10 and 0 units, so we don't really need to use our last finger ...The Base 10 number system consists of 10 different values,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9. This is the same for any number system - the base tells you how many symbols are available to represent things. This is OK up to Base 10 but what single character do we use to represent 10, 11, 12 etc?
When we write numbers, we should
always include the base they are in. For instance, the number 1101 is ambiguous - I could assume that it's written in denary, but this may not be the case ...- 1010
_{2} - 1010
_{8} - 1010
_{10} - 1010
_{16}
... all represent different number of 'things' (10, 520, 1010 and 4112 things respectively).
Counting on your fingers (See this website)Normally, when we count, we use each finger to represent just one 'thing'. This can be severely limiting when it comes to counting a large number of things because we quickly run out of fingers! How would it be different if we could use one finger to represent each available symbol in our base? That means we could use one finger to represent each place (and it's associated value) in the number rather than just one value.
Consider, then two situations ...
... which goes some way to explain why computers count in binary.
So, why do computers use Binary? (
Hint : because they are made of switches)[Why Binary?]
Now that we understand the concept of place value, conversions are easy and best explained by example ...
Binary to Denary[Your teacher may well demonstrate this as well]
Denary to Binary[Your teacher may well demonstrate this as well]
Hexadecimal simply provides a convenient way of representing long binary strings.
One hexadecimal digit is used to represent 4 bits, or a nybble, in our binary string. For reference ...
Binary to hexadecimal conversion[Your teacher may well demonstrate this as well]
Hexadecimal to binary conversion[Your teacher may well demonstrate this as well]
How about these?
**Binary to denary conversion program** Write a program to input a binary number as a text string, convert it to denary and output the result. You may use the following algorithm:
`Output "Enter a binary number "`
`Input BinaryString`
`BinaryLength ← Length of BinaryString`
`Multiplier ← 1`
`DenaryValue ← 0`
`For n ← BinaryLength Down To 1`
`Digit ← nth character in BinaryString`
`DenaryValue ← DenaryValue + Digit * Multiplier`
`Multiplier ← Multiplier * 2`
`Next n`
`Output "The denary equivalent is ", DenaryValue`
Note: Line seven requires a function that returns the nth character from a string. It may also need a function to convert this character to an integer.
Could you adapt this so that it can handle different number bases?
**Denary to binary conversion program**
Write a program to input a denary number, convert it to binary and output the result. You may use the following algorithm which employs integer division:
`Output "Enter a denary number "`
`Input DenaryValue`
`BinaryString ← ""`
`While DenaryValue > 0`
`BinaryString ← CStr(DenaryValue MOD 2) + BinaryString`
`DenaryValue ← DenaryValue DIV 2`
`Endwhile`
`Output "The binary equivalent is ", BinaryString`
Note: The function CStr converts a number to a string. The sign ‘+’ here represents concatenation.
**Poster competition**
Create a poster about binary : research and include simple binary rules, jokes, binary watches / clocks, comics …
**The Octal number system**
One other commonly used number system is Octal, or Base 8, since octal can be used to represent 3 bits where hexadecimal is used to represent 4. Read more about Octal on it's Wikipedia page. One particularly interesting fact is that the Yuki people from America count in Octal because they count using the gaps between the fingers rather than the fingers themselves.
END OF TOPIC ASSESSMENT |