Bits of Bytes.co

IGCSE / GCSE Computer Science

  • Home
  • 1 - Theory of Computer Science
  • 2 - Practical Problem Solving and Programming
  • Pre-Release Material
    • 2018 June >
      • 22 >
        • 22 - Cow Task
        • 22 - Task 1
        • 22 - Task 2
        • 22 - Task 3
  • 1 - Computer Systems (2023)
Picture
MENU
  • Home
  • 1 - Theory of Computer Science
  • 2 - Practical Problem Solving and Programming
  • Pre-Release Material
    • 2018 June >
      • 22 >
        • 22 - Cow Task
        • 22 - Task 1
        • 22 - Task 2
        • 22 - Task 3
  • 1 - Computer Systems (2023)
1 - Theory of Computer Science/  Using Binary

Using Binary Numbers



Hopefully by now you understand what the binary number system is and how / why computers use it, If not you should probably check out the Binary numbers ​page before continuing here. If you do know these things then great! we are ready to find out about the many uses computers have for binary numbers. Use the tabs below to read about the use of binary in registers and character sets.

  • Registers
  • ASCII / Character Sets
<
>

Registers

In register plays an important role whenever a computer (Microprocessor) is required to take control of a device.  Such devices could be digital clocks, drones, robots, air conditioning etc.

Essentially a register is a collection of bits, each bit serving the purpose of switching something on or off, see below for an example of a register scenario:

Digital Display Scenario

In the scenario below you will see that a digital display has 7 segments,  the microprocessor can alter which segments are on or off in-order to produce a desired number.

In the image below you can see that each segment has been labelled from 1 - 7 and that segments 1, 2 and 3 are lit up to make the number 7!
Picture

​The Register


The register that makes this happen can be seen below.  The top row (Green) is labelled from 1 - 7, each number corresponds to the display segment.

The second row contains the binary numbers (Register) that control this device.  For this to work correctly a number 1 is placed in position under any segment that needs to be lit up whereas a 0 is placed under any segment that remains un lit. 
1
2
3
4
5
6
7
1
1
1
O
O
O
O
What to Expect

In the exam you will be presented with a similar to scenario to the one above.  All of the information that is required to answer the question will be provided, it is important that you read the question carefully and ensure that you fully understand how the register works before answering.

ASCII / Character Sets

Character sets are a list of recognized characters that can be recognized and used by a computer.  In a character set each character is represented by a denary number, Binary number and Hexadecimal number.


Picture
One of the most common Character sets is ASCII - American Standard Code for Information Interchange.

Each character on your keyboard is represented by a binary number, this means that when, for example you press the "H" key, the binary number 01001000 is sent to the CPU.  The CPU will then check the ASCII table to see which character this is before outputting it in the desired location.

CLICK HERE to view the ascii table

Number of bits


​Originally ASCII used only 7 bits to represent each character, this allowed for 128 different characters to be represented... this quickly became too little so an extra bit was added.  ASCII now uses 8 bits to represent each character.
A Common Mistake!
A common question that may be asked is to work out how much memory would be required to store a string. Remember that each character is represented by 1 byte.

How many bytes would be required to store the following phrase "Bits of Bytes!"?

The wrong answer would be 11 bytes

The correct answer is 14 Bytes - It is important to remember that every space and character (!) are also to be represented by bytes.

Ascii and Code


​After studying the ASCII table you will have noticed that the table includes numbers.  In the ASCII table, these numbers are actually treated as characters.  Each of these characters is represented by a denary number and a binary number, see the table below:
ASCII Character
Binary Value
Denary Value
O
00110000
48
1
00110001
49
2
00110010
50
3
00110011
51
4
00110100
52
5
00110101
53
6
00110110
54
7
00110111
55
8
00111000
56
9
00111001
57
Looking at the table above, it is easy to see why some confusion may occur.  Example -The character "1" is actually representing the denary number 49... and to make things worse, this 1 is actually being treated as a string and not an integer.

This can cause an issue in programming if data types are not correctly stated.  Take to following code as an example:
​
ASCII problem

    
When this code is executed the output will be:

Total = 35

This is most likely not the expected result, we were actually expecting - Total = 8.

The problem here is that num1 and num2 were storing 3 and 5 as strings, not integers.  This is evident by the Quotation marks that are around the numbers.  As they are being treated as strings it means that they are literally characters from the ASCII table.  Characters cannot be added together, but placing a + beteen them will combine them into one string.  This is known as concatenation.

​To fix this issue you will have to ensure that the data in the num1 and num2 variables are treated as Integers.  This could be done either whilst declaring the variable or by casting the variable using a function.  Both methods are demonstrated below.
​
 ASCII problem fix

    
Both of these methods would produce the output:

Total = 8

The INT() function simply converts the data within its brackets into an Integer.  STR()  can be used to convert data into a string.

Unicode


Being able to represent only 256 characters is fine for the English language, however, as we know there are many languages in the world that use different letters e.g. Russian, Chinese...

There needs to be a character set to allow for these letters and other characters to be represented and that is what unicode is for.

Unicode uses 16 bits to represent each character, this allows for up to 65,536 different characters to be represented... more than enough for every language and some special characters. ☺
Picture

Est. 2015 - Copyright © 2020