IB/Group 4/Computer Science/Computer Organisation/The Information Layer

What is positional notation ?

edit

Numbers are written using positional notation. The rightmost digit represents its value multiplied by the base of the zeroth power. The digit to the left of that one represents its value multiplied by the base to the first power. The next digit represents its value multiplied by the base to the second power. The next digit represents its value multiplied by the base to the third power, and so on. One is usually familiar with positional notation even if they are not aware. One is instinctively inclined to utilise this method to calculate the number of ones in 943:

                 
                   
                   
 

A more formal way of defining positional notation is to say that the value is represented as a polynomial in the base of a number system. But what is a polynomial? A polynomial is a sum of two or more algebraic terms, each of which consists of a constant multiplied by one or more variables raised to a non-negative integral power. When defining positional notation, the variable is the base of the number system. Thus 943 is represented as a polynomial as follows, with   acting as the base:

 

To express this idea formally, a number in the base-  number system has   digits, it is represented as follows, where   represents the digit in the  th position in the number:

 

Look complicated? Take a concrete example of 63578 in the base 10. Here   is 5 (the number has exactly 5 digits), and   is 10 (the base). The formula states that the fifth digit (the last digit on the left) is multiplied by the base to the fourth power; the fourth digit is multiplied by the base to the third power, and so on:

 

In the previous calculation, one assumed that the number base is 10. This is a logical assumption because the generic number system is base 10. However, there is no reason why the number 943 could not represent a value in base 13. In order to distinguish between these values, the general notation of   is utilised in order to represent a number   in base  . Therefore,   is a number found in the base 10 system. In order to turn turn   into   one simply uses the previous calculation:

                 
                   
                   
 

Therefore, 943 in base 13 is equal to 1576 in base 10, or  . One must keep in mind that these two numbers have an equivalent value. That is, both represent the same number of "things." If one bag contains   beans and a second bag contains   beans, then both bags contain the exact same number of beans. The number systems just allow one to represent the value in various ways.

Note that in base 10, the rightmost digit is the "ones" position. In base 13, the rightmost digit is also the "ones" position. In fact, this is true for any base, because anything raised to the power of zero is one.

Why would anyone want to represent values in base 13? It is not done very often, granted, but it is sometimes helpful to understand how it works. For example, a computing technique called hashing takes numbers and scrambles them, and one way to scramble numbers is to interpret them in a different base.

Other bases, such as base 2 (binary), are particularly important in computer processing. It is also helpful to be familiar with number systems that are powers of 2, such as base 8 (octal), and base 16 (hexadecimal).


Binary

edit

What is binary ?

edit

The term binary refers to any encoding in which there are two possible values. In computer science they refer to the electronic values 0 and 1 (see figure below). Booleans values are binary. In computers we use binary instead of the decimal system as they offer a much simpler and efficient way to perform calculations through electronics than they would with a decimal system. This can be explored in the following sections regarding binary gates.

 
Image: 150 pixels

Interpretation of voltages to binary by the computer. Given that we are in a system where the max voltage is 5 Volts, then input current in an electrical wire is interpreted as a logical 0 by a transistor if the voltage is between 0 volts and 0.8 volts. On the other hand if the voltage is between 2 volts and 5 volts then the transistor interprets the input signal as a logical 1 (right diagram). It is important to note that there is a non-usable area of voltage that does not correspond to either a logical 0 or 1. This non-usable area is particularly useful since voltage always slightly fluctuates, having this grey zone allows us to better identify electrical signals (0 and 1) from each other. Similar voltage conversions from volts to binary digits also exist for output signals from transistors.¹

The base of a number system specifies the number of digits used in the system. The digits always begin with 0 and continue through one less than the base. For example, there are 2 digits in base 2: 0 and 1. There are 8 digits in base 8: 0 through to 7. There are 10 digits in base 10: 0 through 9. The base also determines what the positions of digits mean. When one adds 1 to the last digit in the number system, one has to carry the digit position to the left.

What is a bit ?

edit

A bit is the smallest unit of data that a computer can process and store. It can either store a 1 or a 0 and represents on/off, true/false, yes/no.

What is a byte ?

edit

1 byte is a unit of data that consists of/stores 8 bits. 1 byte represents 28 distinct values.

How do I convert a decimal number to a binary number ?

edit

If we want to convert a decimal number to a binary number we will also use our previous conversion table.

For example let's convert decimal number 56:

  • First we look at the biggest binary power that can entirely fit in 56. This is 32 = 25. It is not 64 because 56 does not fit entirely into 64.
  • Then we take the remainder of 56 - 32 = 24. We check which is the biggest binary power that can entirely fit into 24. This is 16 = 24.
  • Then we take the remainder of 24 - 16 = 8. We check which is the biggest binary power that can entirely fit into 24. This is 8 = 23.
  • Finally 8 - 8 = 0 so we have reached the end.

Now we mark the powers of two that we used for our calculus as a binary 1 and the other powers as 0. We get 00111000

decimal to binary conversion table
27 26 25 24 23 22 21 20
= 128 64 32 16 8 4 2 1
= 0 0 1 1 1 0 0 0


How do I convert a binary number to a decimal number ?

edit

To convert a binary number into decimal, we just need to sum all powers of 2 that have a 1 in the binary digit.

First off, we must count the number of digits in the Binary Number and correlate them with the powers of 2, starting from   up to  .

For each digit in binary we must take multiply the number by the corresponding exponent of 2. For example:

Take the binary number 1011. Following the previous rule of positional number we achieve the following table:

                 
                   
                   
                   
 

Now following the same logic, but just written differently, if we convert the following byte into decimal: 10011100

binary to decimal conversion table
1 0 0 1 1 1 0 0
= 27 26 25 24 23 22 21 20
= 128 64 32 16 8 4 2 1
= 128 16 8 4

We only add the columns where the binary digit is equal to 1.

Finally, we add each number up and this is the number converted from binary.

So 10011100 = 128 + 16 + 8 + 4 = 156

How many possible numbers can I store in a byte ?

edit

A byte is 8 bits, which means that the amount of values that can be stored in a byte of data is 28 = 256.

How many possible numbers can I store in a an n-bit number ?

Since there are n possible bits that each can take two possible values (1 or 0), we can store   possible numbers in a n-bit number.

In a byte this means we can store 28 = 256 different numbers.

What is the biggest number I can get in a an n-bit number ?

Since there are n possible bits that each can take two possible values (1 or 0), the biggest number that we can get is 2n -1. Indeed the smallest number that we can get is a 0 hence the -1 in the formula.

In a byte this means the biggest number we can get is 28 -1 = 255, being 11111111, and the smallest number is 0 being 0000000.

Exercises - Binary representation of numbers

edit

1. What is the decimal representation of 1001 ?

23 + 20 = 8 + 1 = 9

2. What is the decimal representation of 01000101 ?

26 + 22+ 20 = 64 + 4 + 1 = 69

3. What is the binary representation of 42 ?

42 - 32 = 10 with 32 = 25

10 - 8 = 2 with 8 = 23

2 - 2 = 0 with 2 = 21

Hence the binary representation: 00101010

4. What is the binary representation of 129 ?

129 - 128 = 1 with 128 = 27

1 - 1 = 0 with 1 = 20Hence the binary representation: 01000001

5. How many different integers can I represent in 2 bytes ?

2 bytes are 16 bits (2 x 8bits), hence 216 = 65536 different numbers can be represented in 2 bytes

6. What is the biggest number I can represent in 2 bytes ?

2 bytes are 16 bits (2 x 8bits), hence 216 -1 = 65535 is the biggest number that can be represented in 2 bytes.

Hexadecimal

edit

What is Hexadecimal ?

edit

How are digits represented in bases higher than 10? In bases higher than 10, the digits above the integer 9 will be represented as symbols. All digits are written in the following conversion table.

decimal hexadecimal binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111

Hexadecimal is a numbering system that uses 16 possible digits. Its primary attraction is its ability to represent very high numbers with fewer digits that in binary or in the decimal system.

How do I convert a decimal number to a hexadecimal number ?

edit

The method is following:

  • Apply a floor division to the decimal number by 16. Write down the remainder starting from the left side.
  • Continue applying floor division by 16 to the previous result of the floor division until you reach 0. Keep writing down the remainders.
  • Convert the remainders, from last one to first one, to hexadecimal using the table to the right.
  • You have your hexadecimal number !

For example if we want to convert the decimal number 2545 to hexadecimal:

  • We apply floor division: 2545 // 16 = 159, The remainder of that division is 2545 % 16 = 1
  • We apply floor division to our previous result: 159 // 16 = 9, The remainder of that division is 159 % 16 = 15
  • We apply floor division to our previous result: 9 // 16 = 0, The remainder of that division is 9 % 16 = 9.
  • We reached 0 so we stop dividing.
  • We convert our remainders: 9 → 9, 15 → F, 1 → 1
  • So our hexadecimal number is: 9F1


How do I convert a hexadecimal number to a decimal number ?

edit

This conversion is a bit simpler as we can use positional notation to convert our number. Indeed, we just need to multiply each hexadecimal digit by its corresponding power of 16.

For example, if we want to convert the hexadecimal number ABC to a decimal number we multiply   by   as there are 12 ones in the number,   by   as there are 11 sixteens, and   by   as there are 10 two-hundred-fifty-sixes.

                 
                   
                   
 

How do I convert a binary number to a hexadecimal number?

edit

To convert a binary number to a hexadecimal number, start by making sure the length of your binary number is a multiple of 4. If not, add 0s to the front of the number until it is a multiple of 4.

Next, split the binary number into groups of 4 digits.

Then, for each group of 4 digits, turn the binary number into a single number, by converting each digit in the 4-digit values to the corresponding power of 2:

(The thousands becomes 8, the hundreds becomes 4, the tens becomes 2, and the units becomes 1. However, if the binary value at a place is a 0, then it stays a zero.)

For instance, the binary value 1111 becomes 8421, while 0101 becomes 0401

Then, add up the digits. 8421 becomes 8+4+2+1 = 15, while 0401 becomes 4+1 = 5.

Finally, convert that value to hexadecimal. If the value is from 0 to 9, it stays that value in hexadecimal. If it is 10 or higher, it changes to the corresponding alphabet letter: 10 is A, 11 is B, et cætera.

For example if we want to convert the binary number: 1011111011

  • Our number has only 10 bits so we add two 0s to the left side: 001011111011
  • We divide our number in groups of 4 bits: 0010 1111 1011
  • We turn each group into a single number: 0+0+2+0 = 2, 8+4+2+1 = 15, 8+0+2+1 = 11
  • We convert the single number to hexadecimal numbers: 2 → 2, 15 → F, 11 → B
  • Our hexadecimal number is 2FB

Octal

edit
Note

Not needed for the exam



What is Octal ?

edit
Not needed for the exams

Octal is a numbering system in base 8, meaning only digits from 0 to 7 exist in this notation.

For example, one can calculate the decimal equivalent of 754 in octal (base 8) − simply put, finding  . As before, it is the case of expanding the number in its polynomial form and adding up the numbers:

                 
                   
                   
 

Representing Text

edit

What is ASCII?

edit
 
The original 7-bit ASCII table (English version)

ASCII stands for American Standard Code Information Interchange. It was a 7-bit code, later changed to 8-bit, that had the purpose of setting a number to a letter and other foreign symbols which would allow for the interchanging of information between computers in a single country or using the same language. The total number of letters and symbols stored in ASCII was 128. Countries would input their own letters and symbols instead of English.

However, there was one major drawback, the fact that ASCII only held symbols with English letters, computers from around the world could not successfully interchange information and data with each other.

This drawback led to the creation of the larger database of letters and symbols, Unicode which allows all languages to store their letters in Unicode.

What is Unicode ?

edit
 

Though ASCII was the industry standard for a very long time, it simply did not have enough characters and symbols to cover the fast internationalisation of the world. The initial solution was to have a different organisation system per country, however if a person in Japan were to send a email with Japanese characters to someone in the UK it would be an incomprehensible mess. The solution was Unicode. Unicode now build on a 16-24 bit systems instead of ASCII's 8 bit system and is able to cover 149,813 different characters, which is enough to cover every single character in every single language that exists.

As of 2024, a total of 161 scripts are included in the latest version of Unicode (covering alphabets, abugidas and syllabaries), although there are still scripts that are not yet encoded, particularly those mainly used in historical, liturgical, and academic contexts. Further additions of characters to the already encoded scripts, as well as symbols, in particular for mathematics and music (in the form of notes and rhythmic symbols), also occur.

What is UTF-8 ?

edit

UTF-8 is a way of translating between Unicode characters and binary text. This is done by storing each Unicode character in the form of up to four one-byte binary strings. Each binary string is created by converting the code point of the Unicode character (letters and numbers that form an index) into a set of binary strings, where each string represents one character in the code point.

For example, the character "A", is represented as `"U+0041" (where "41" is the code point), which is encoded to "01000001" (which is 41 in hexadecimal).

How can I represent characters from different languages in a text?

edit

The best way to represent characters from different languages is to use Unicode. ASCII is inconvenient for different languages as it was designed specifically for English, and does not contain any non-English characters. Meanwhile, Unicode has Chinese, Japanese, and Korean characters, the Cyrillic and Arabic alphabets, as well as any other symbol from a wide variety of languages.

Representing Floating point numbers

edit
Note

Not needed for the exam


How are floats represented/stored ?

edit
Section to go more in-depth on the content.

Floats are typically represented in 4 bytes. Out of these 32 bits: 1 bit is used for the sign of the number, 8 bits are used for the exponent and 23 bits are used for the floating point of the number. It is a way of storing numbers in scientific notation.

 

Putting the values into mathematical terms, it is calculated by ±A* . The sign is represented by the blue area, A is given by the red area and B is given by the green area.

It is interesting to note that if we want to represent negative and positive numbers (whole numbers or decimal) we need to use one bit for storing the sign. If we only store positive numbers we don't need to keep that sign bit.

Representing sound

edit
Note

Not needed for the exam


How is sound represented/stored ?

edit

After sound has been recorded with a microphone, which converts sound waves into a digital signal, computers use a technique called sampling. The computer samples the sound by taking measurements of the amplitude of the sound signal at regular intervals, often 44.1 kHz (or 44,100 times per second), which are then saved as numbers in binary format.

How does the mp3 file format store and represent sound ?

edit

Representing images

edit

How are colors represented/stored ?

edit

Colors we see on the computer screens today are represented by binary numbers of 24 bits.


As we know, all colors originate from the 3 primary colors red, blue, and green. Depending on how much of the 3 colors we mix, we are able to achieve many different colors. Therefore, the computer only analyses the 3 primary colors and how much they are used when being mixed. This system is called an RGB representation.

In the total of 24 bits, we divide it into 3 sets of bits for the 3 different primary numbers: 8 bits are for blue, 8 bits are for green, and 8 bits are for red.


Let's first take an example of the color red. In the color red, the corresponding RGB value is: R - 255 (most amount of color we can use), G - 0 (using none of this color), B - 0 (using none of this color).

Therefore, in the 8 bits, the number 255 in base 10 can be transformed into base 2 in 8 bits, which is in this case 11111111. Hence the color red in binary of 24 bits would be 111111110000000000000000. This case applies for both green (000000001111111100000000) and blue (000000000000000011111111).


To summarize, here are the steps:

- divide the 24 bits into 3 sets of 8 bits to represent the colors red, green, and blue

- find the RGB representation of the color in base 10

- transform each the RGB values that are in base 10 to base 2

- combine the 3 sets of 8 bits and here we have the final binary representation of a color


Generally, 24 bits are sufficient to depict realistic colors (photo-realistic). However, even more bits can be used such as 32 bits or 48 bits to illustrate even more realistic colors.

What is a pixel ?

edit

How does the .png file format store and represent images ?

edit

How does the .jpeg file format store and represent images ?

edit

Exercises

edit

Write the hexadecimal number F12 in denary and binary.

Correction

Denary: 3858

Binary: 111100010010


Represent the denary number 123 in hexadecimal and binary.

Correction

Hexadecimal: 7B

Binary: 1111011


Write the hexadecimal number F0A in decimal.

Correction

3850