9618 Computer Science
AS Content
Chpater 1 Information representation
1.1 Data representation
1.2 Multimedia
1.3 Compression
Chapter 2 Communication
2.1 Networking
2.2 The internet
Chpater 3 Hardware
3.1 Computers and their components
3.2 Logic Gates and Logic Circuits
Chapter 4 Processor Fundamentals
4.1 Central Processing Unit (CPU) Architecture
4.2 Assembly Language
4.3 Bit manipulation
Chapter 5 System Software
5.1 Operating Systems
5.2 Language Translators
Chapter 6 Security, privacy and data integrity
6.1 Data Security
6.2 Data Integrity
Chpater 7 Ethics and Ownership
7.1 Ethics and Ownership
Chapter 8 Databases
8.1 Database Concepts
8.2 Database Management Systems (DBMS)
8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)
Chapter 9 Algorithm Design and Problem-solving
9.1 Computational Thinking Skills
9.2 Algorithms
Chapter 10 Data Types and Records
10.1 Data Types and Records
10.2 Arrays
10.3 Files
10.4 Introduction to Abstract Data Types (ADT)
Chapter 11 Programming
11.1 Programming Basics
11.2 Constructs
11.3 Structured Programming
Chapter 12 Software Development
12.1 Program Development Life cycle
12.2 Program Design
12.3 Program Testing and Maintenance
A2 Content
Chapter 13 Data Representation
13.1 User-defined data types
13.2 File organisation and access
13.3 Floating-point numbers, representation and manipulation
Chpater 14 Communication and internet technologies
14.1 Protocols
14.2 Circuit switching, packet switching
Chpater 15 Hardware
15.1 Processors, Parallel Processing and Virtual Machines
15.2 Boolean Algebra and Logic Circuits
Chapter 16 Operating System
16.1 Purposes of an Operating System (OS)
16.2 Translation Software
Chpater 17 Security
17.1 Encryption, Encryption Protocols and Digital certificates
Chpater 18 Artificial intelligence (AI)
18.1 Artificial Intelligence (AI)
Chapter 19 Computational thinking and problem solving
19.1 Algorithms
19.2 Recursion
Chapter 20 Further programming
20.1 Programming Paradigms
20.2 File Processing and Exception Handling
Mr. Theo
-
+
首页
1.1 Data representation
# Data representation - The basis of any number system consists of: - A base: the number of digits that a number systemcan use to represent numbers - Place value for each digit: digits in certain positionshave a specific value - Denary - Base 10 integer digits - Binary Systems - Base 2 - Possible bits (binary digits): 0 and 1 - All data and characters are represented in binary #### Converting from binary to denary ##### Example: binary number 10011011 | Place value | 2<sup>7</sup>=128 | *2*<sup>6</sup>=64 | 2<sup>5</sup>=32 | *2*<sup>4</sup>=16 | 2<sup>3</sup>=8 | 2<sup>2</sup>=4 | 2<sup>1</sup>=2 | 2<sup>0</sup>=1 | | :------------------------------: | :---------------: | :----------------: | :--------------: | :----------------: | :-------------: | :-------------: | :-------------: | :-------------: | | Digit | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | | Product of digit and place value | 128 | 0 | 0 | 16 | 8 | 0 | *2* | 1 | *Adding up the values in the bottom row* *:128 + 16 + 8 + 2 + 1=155* ##### Example: binary number 011110001011 | Place value | 2<sup>11</sup>=2048 | 2<sup>10</sup>=1024 | 2<sup>9</sup>=512 | 2<sup>8</sup>=256 | 2<sup>7</sup>=128 | 2<sup>6</sup>=64 | *2*<sup>5</sup>=32 | 2<sup>4</sup>=16 | 2<sup>3</sup>=8 | 2<sup>2</sup>=4 | 2<sup>1</sup>=2 | 2<sup>0</sup>=1 | |:--------------------------------:|:-------------------:|:-------------------:|:-----------------:|:-----------------:|:-----------------:|:----------------:|:------------------:|:----------------:|:---------------:|:---------------:|:---------------:|:---------------:| | Digit | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | | Product of digit and place value | 0 | 1024 | 512 | 256 | 128 | 0 | 0 | 0 | 8 | 0 | 2 | 1 | *Adding up the values in the bottom row* *:* *1024 + 512 + 256 + 128 + 8 + 2 + 1 = 1931* #### Converting from denary to binary ##### *The conversion of the denary number, 142, into binary* ###### Method 1 The denary number 142 is made up of *128* *+* *8* *+* *4* *+* *2* (that is, 142 – *128* *= 14; 14 –* *8* *= 6;* *6 –* *4* *= 2; 2 –* *2* = 0; in each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached. This will give us the following 8-bit binary number: | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:| | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | ###### Method 2 This method involves successive division by 2. Start with the denary number, 142, and divide it by 2. Write the result of the division including the remainder (even if it is 0) under the 142 (that is, 142 ÷ 2 = 71 remainder 0); then divide again by 2 (that is, 71 ÷ 2 = 35 remainder 1) and keep dividing until the result is zero. Finally write down all the remainders in reverse order: | 2 | 142 | | | |:---:|:---:|:---------:|:---:| | 2 | 71 | Reminder: | 0 | | 2 | 35 | Reminder: | 1 | | 2 | 17 | Reminder: | 1 | | 2 | 8 | Reminder: | 1 | | 2 | 4 | Reminder: | 0 | | 2 | 2 | Reminder: | 0 | | 2 | 1 | Reminder: | 0 | | | 0 | Reminder: | 1 | read the remainders from bottom to top to get the binary number: *1 0 0 0 1 1 1 0* #### Binary Negative numbers: Two's complement ##### There are a number of methods to represent both positive and negative numbers. We will consider: - one’s complement.二进制反码 - two’s complement.二进制补码 In one’s complement, each digit in the binary number is inverted (in other words, 0 becomes 1 and 1 becomes 0). ###### Example: What is – 6510 in binary? Step 1: ``` 65 = 01000001 in binary ``` Step 2: invert 1 to 0 and 0 to 1 we get: 01000001 to its one’s complement as below: ``` 01000001 = 10111110 ← one’s complement ``` In two’s complement, binary digit 1 is added to one’s compliment Step 3: Convert 10111110 Binary to its two’s complement by adding 1 to the one’s complement. ``` 1011 1110 ← one’s complement + 1 ----------- 1011 1111 ← Two's complement ``` Two’s compliment of a positive number will make it a negative number | *Place values* | -128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | | ------------------ | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | | *Two's complement* | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | = -128 + 32 +16+8+4+2+1 = - 65 *10111111 is - 65 in binary. We know this it true because if we add* *01000001 (+65) to 10111111b (-65) and ignore the carry bit, the sum is 0,* *which is what we obtain if we add +65 + (-65) = 0.* ``` 0100 0001 ← +65 + 1011 1111 ← -65 ----------- 1 0000 0000 ``` Ignore the carry bit. What matters is that original number of bits (D7-D0) are all 0. #### Overflow A CPU with a capacity of 8 bits has a capacity of up to 11111111 in binary. If one more bit was added there would be an overflow error. *An explanation of binary overflow errors* *Example: 8-bit overflow* ``` 1111 1111 + 0000 0001 ------------- 1 1111 111 ← carry values 1 0000 0000 ← sum values ``` *An example of an 8-bit overflow occurs in the binary sum 11111111 + 1 (denary: 255 + 1).* *The total is a number bigger than 8 digits, and when this happens the CPU drops the overflow* *digit because the computer cannot store it anywhere, and the computer thinks 255 + 1 = 0.* #### Negative numbers: Sign and magnitude 1 0 0 0 1 0 0 1 - the **bit** at the far left of the bit pattern - the **sign bit** indicates whether the number is positive or negative. - The rest of the bits in the pattern store the size of the number (called its **magnitude**). With an 8-bit pattern, the first bit would be used to indicate positive or negative. 0 can indicate a positive number and a 1 can indicate a negative number. The other seven bits would be used to store the actual size of the number. ###### For example, 10001001 could represent –9. *The* *smallest* *possible number* *using this method of representation is -128 (or 1000 0000)* *and the* *largest* *possible number is* *+127 (or 01111111).* #### Binary Addition (unsigned number) Adding binary numbers is similar to adding denary numbers. ###### Example: Adding the binary numbers 011 and 100. Write the numbers out using the column method. Start from the right, and simply add the Numbers. ``` 011 + 100 ------------- 111 ← sum values ``` 111 is 7 if converted back to denary. ###### Example: Adding two 1s in the same column. Sometimes a binary addition will require you to carry over values into the next highest place value column, eg when finding the sum of the binary numbers 0010 and 0111: There is a clash when adding two ones in the same column. In binary, 1+1 is 10 it has to become 0 with 1 carried over. ``` 0010 + 0111 ------- 11 ← carry values 1001 ← sum values ``` 1001 is 9 if converted back to denary. 2 + 7 = 9 in denary. #### Binary addition (signed number) Add 0 0 1 0 0 1 0 1 (37 in denary) and 0 0 1 1 1 0 1 0 (58 in denary). ``` -128 64 32 16 8 4 2 1 0 0 1 0 0 1 0 1 + 0 0 1 1 1 0 1 0 --------------------------------- 1 ← carry values 0 1 0 1 1 1 1 1 ← sum values ``` #### Binary Subtraction: - Subtraction of binary numbers is an arithmetic operation similar to the subtraction of decimal numbers or base 10 numbers. For example, 1 + 1 + 1 = 3 in base 10 and 1 + 1 + 1 = 11 in binary number system. - When you add and subtract binary numbers, you will need to be careful when borrowing as these will take place more often. - When you subtract several columns of binary digits, you must take into account the borrowing. When 1 is to be subtracted from 0, the result is 1 where 1 is borrowed from the next highest order bit or digit. ##### Method 1: Binary subtraction using binary numbers ###### *Binary Subtraction Table* *The subtraction of binary numbers is given by:* | Binary Number | Subtraction Value | | ------------- | ---------------------------------------- | | 0 - 0 | 0 | | 1 - 0 | 1 | | 0 - 1 | 1 (Borrow 1 from next high order digit) | | 1 - 1 | 0 | ###### *Procedure to do Binary Subtraction:* ###### Example 1: 0011010 – 001100  ###### Example 2: 0100010 – 0001010  ##### Method 2: Binary subtraction converting denary numbers to binary numbers - To carry out subtraction in binary, we convert the number being subtracted into its negative equivalent using two’s complement, and then add the two numbers. ###### Example 1:  ###### Example 2: 00000011−01100100 **1** 00000011−01100100 = 00000011+(−01100100) **2** Find the two's complement of −01100100 ``` 1 0 0 1 1 0 1 1 ← Invert the digits 0110 0100 + 1 ← Add 1 ------------------- 1 ← carry values 1 0 0 1 1 1 0 0 ← sum values ``` **3 Add** 00000011 and 10011100: ``` -128 64 32 16 8 4 2 1 0 0 0 0 0 0 1 1 + 1 0 0 1 1 1 0 0 --------------------------------- 1 0 0 1 1 1 1 1 ← sum values ``` #### #### Measurement of the size of computer memories *Bits can be grouped together to make them easier to work with. A group of 8 bits is* *called a byte.* | DenaryPrefix | Factor value | BinaryPrefix | Factor value | | ------------ | ----------------- | ------------ | ---------------- | | kilo-(k) | × 10<sup>3</sup> | kibi-(Ki) | × 2<sup>10</sup> | | mega-(M) | × 10<sup>6</sup> | mebi-(Mi) | × 2<sup>20</sup> | | giga-(G) | × 10<sup>9</sup> | gibi-(Gi) | × 2<sup>30</sup> | | Tera-(T) | × 10<sup>12</sup> | tebi-(Ti) | × 2<sup>40</sup> | - Base 10 system usually used in Electronic equipment manufacturer - Base 2 system usually used in computer systems - Nibble - 4 bits (half a byte) - Byte - 8 bits - Kibibyte (KiB) - 1024 bytes (or 1024 x 8 bits) = 2<sup>10</sup> - Mebibyte (MiB) - 1024 Kibibytes (or 1048576 bytes) = 2<sup>20</sup> - Gigibyte (GiB) - 1024 Mebibyte = 2<sup>30</sup> - Tebibyte (TiB) - 1024 Gigibyte = 2<sup>40</sup> - Hexadecimal Number System: Base 16 - Easier to debug as it is close to human language - Reduces errors as less digits to write - Possible digits: 0 to 9 and A to F, where A to Frepresent denary digits 10 to 15 - Practical applications: - Defining colours in HTML - Defining Media Access Control (MAC) addresses - Assembly languages and machine code - Debugging via memory dumps ##### Hexadecimal Number Place Value | *1048576* | *65536* | *4096* | *256* | *16* | *1* | | --------- | ------- | ------ | ----- | ---- | ---- | | 165 | 164 | 163 | 162 | 161 | 160 | #### Converting from hexadecimal to denary Example: 1 A 9 B | *P**lace value* | *16*<sup>3</sup>*=4096* | *16*<sup>2</sup>*=256* | *16*<sup>1</sup>*=16* | *16*<sup>0</sup>*= 1* | | ------------------------------------ | ------------------------- | ------------------------ | ------------------------- | ----------------------- | | *Digit* | *1* | *A=10* | *9* | *B=11* | | *Product of digit and* *place value* | *4096* | *2560* | *144* | *11* | 1 A 9 B<sub>16</sub> = 4096 + 2560 + 144 + 11 = 6811<sub>10</sub> #### Converting from denary to hexadecimal - This method involves successive division by 16. Start with the denary number, 746, and divide it by 16. - Write the result of the division including the remainder (even if it is 0) under the 746 (that is, 746 ÷ 16 = 46 remainder 10); then divide again by 16 (that is, 46 ÷ 16 = 2 remainder 14) and keep dividing until the result is zero. - *Finally write down* *all the remainders in reverse order:* | 16 | 746 | | | | ---- | ---- | --------- | ------ | | 16 | 46 | Reminder: | 10 = A | | 16 | 2 | Reminder: | 14 = E | | | 0 | Reminder: | 2 | *read the remainders from bottom to top* *to get the hexadecimal number:* *2* *E A* #### Converting from binary to hexadecimal - *Starting from* *the right and moving left, split the binary number into groups of 4 bits.* - *If the* *last group has less than 4 bits, then simply fill in with 0s from the left.* - *Take* *each group of 4 bits and convert it into the equivalent hexadecimal digit.* ###### Example 1: *Convert 1 0 1 1 1 1 1 0 0 0 0 1 from binary to hexadecimal.* ``` 1 0 1 1 1 1 1 0 0 0 0 1 // First split it into groups of 4 bits 1 1 14 1 // Convert to denary B E 1 // Convert to hexadecimal ``` ###### Exampl 2: *Convert 1 0 0 0 0 1 1 1 1 1 1 1 0 1 from binary to hexadecimal.* ``` 1 0 0 0 0 1 1 1 1 1 1 1 0 1 // First split it into groups of 4 bits 0 0 1 0 0 0 0 1 1 1 1 1 1 1 0 1 // The left group only contains 2 bits, so add in two 0s to the left 2 1 15 13 // Convert to denary 2 1 F D // Convert to hexadecimal ``` #### Converting from hexadecimal to binary ###### Example 1: *Convert* ***4 5 A*** *to its binary equivalent.* ``` 4 5 A 4 5 10 // Convert each digit to denary 0100 0101 1010 // Convert each digit to 4-bit binary ``` ###### Example 2: *Convert* ***B F 0 8*** *to its binary equivalent.* ``` B F 0 8 11 15 0 8 // Convert each digit to denary 1011 1111 0000 1000 // Convert each digit to 4-bit binary ``` #### Binary Coded Decimal (BCD) - Binary representation where each positive denary digit is represented by a sequence of 4 bits (nibble) - Only certain digits are converted to BCD, because particular digits represent a digit greater than 9. - Ex. 429 in BCD: - Convert each digit to their binary equivalents - 4 = 0100 | 2 = 0010 |9 = 1001 - Concatenate the 3 nibbles (4-bit group) to produce BCD: 0100 0010 1001 - BCD Addition   - Application of BCD - Performs financial / banking calculations - because it is difficult to represent decimal values exactly in normal binary and financial transactions use only two decimal places and must be accurate, no accumulating errors - Electronic displays, e.g. calculators, digital clocks - because visual displays only need to show individual digits - because conversion between denary and BCD is easier - The storage of the date and time in the BIOS of a PC - because conversion with denary is easier #### Character Sets - All the characters and symbols that can be represented by a computer system; - Each character and symbol is assigned a unique value; | ASCII | Extended ASCII | Unicode | | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | Only English alphabets can be represented | ASCII’s extension - Also includes most European languages’ alphabets | Superset for ASCII & extended ASCII - recognized by various global languages | | Each character encoding takes up 7 bits, hence 128 possible characters | ASCII extended to 8 bits, hence 256 possible characters. | Greater range of characters, as it uses 2 or 4 bytes per character. | | Smaller storage space. | | 2 or 4 times more storage space per character. |
Theo
2025年5月30日 13:24
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
Word文件
PDF文档
PDF文档(打印)
分享
链接
类型
密码
更新密码
有效期