HCI 5. Data Representation
Uploaded by adrianwang2003 · 28 May 2024
Preview
Text from the first pagesHwa Chong Institution H2 Computing 1 5 Data Representation Learning Outcome 5.1 Binary Representation Computers only ‘understand’ 0’s and 1’s. All the data inside a computer has to be represented by patterns of 1’s and 0’s. e.g. 0 1 0 1 1 0 1 0 represents character ‘Z’ in ASCII code 0 0 0 0 0 0 1 1 represents number 3 A bit is a binary digit. It can be a 1 or 0. A byte is taken to represent 8 bits. A word is the number of bytes that can be stored inside a memory location. e.g. A 16-bit computer memory location contents 0 1 1 0 0 0 1 0 1 0 0 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 a bit a byte ( 8 bits) a word ( 16 bits) 5.2 Number Systems System Base Digits Used Used by Decimal (Denary) 10 0,1,2,3,4,5,6,7,8,9 humans Binary 2 0,1 computers Octal 8 0,1,2,3,4,5,6,7 Programmers as Data Representation Represent data in binary and hexadecimal forms Write programs to perform the conversion of positive integers between different number bases: denary, binary and hexadecimal forms; and display results Data Validation Understand data validation technique: check digit
Hwa Chong Institution H2 Computing 2 Hexadecimal 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F ‘shorthands’ for binary A number N with base r is written as N r e.g. 101 2 71 8 19A 16 6925 (Binary) (Octal) (Hex) (Decimal) Place Value: the value of any digit depends on its position in the number. e.g. Decimal number 4957 place value : 10 3 10 2 10 1 10 0 ------------------------------ 4 9 5 7 e.g. Binary number 1101 2 place value : 2 3 2 2 2 1 2 0 -------------------------- 1 1 0 1 The most significant digit (MSD) is the digit with the highest place value in the number. The least significant digit (LSD) is the digit with the lowest place value in the number. e.g. 1 0 0 1 0 2 , 4 9 7 5 10 MSD LSD MSD LSD 5.3 Conversion of a number from one base to another 5.3.1 From decimal to another base Example Convert 79 10 to binary. 2 7 9 remainder 2 3 9 ------ 1 (LSD) 2 1 9 ------ 1 2 9 ------ 1 2 4 ------ 1 2 2 ------ 0 2 1 ------ 0 stopping 0 ------ 1 (MSD) condition
Hwa Chong Institution H2 Computing 3 79 10 = 1 0 0 1 1 1 1 2 Example Convert 79 10 to hexadecimal. 16 7 9 remainder 16 4 ------ F (LSD) 0 ------ 4 (MSD) 79 10 = 4 F 16 note : F 16 is equivalent to 15 10 Method : Divide the decimal number by the new base continuously and note the remainders until the quotient is zero. Arrange the remainders, with the first remainder as the least significant digit and the last remainder as the most significant digit. 5.3.2 From other base to decimal Example Convert 1 0 0 2 to decimal place value: 2 2 2 1 2 0 ------------------ 1 0 0 1 0 0 2 = ( 1 * 2 2 ) + ( 0 * 2 1 ) + ( 0 * 2 0 ) = 410 1 0 0 2 = 4 10 Example Convert 6 D 16 to decimal place value: 16 1 160 ------------ 6 D 6 D 16 = ( 6 * 16 1 ) + ( D * 16 0 ) = ( 6 * 16 1 ) + ( 13 * 16 0 ) = 109 10 6 D 16 = 109 10
Hwa Chong Institution H2 Computing 4 Method: Multiply each digit by its place value and then sum up the products. 5.3.3 From binary to hexadecimal and vice versa Example Convert 1 0 1 0 1 0 0 1 0 1 0 1 1 1 2 to hexadecimal By sectoring in group of four 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 1 (base 2) 2 A 5 7 (base 16) 1 0 1 0 1 0 0 1 0 1 0 1 1 1 2 = 2 A 5 7 16 Example Convert 1 1 1 0 0 2 to hexadecimal By sectoring in group of four 0 0 0 1 1 1 0 0 (base 2) 1 C (base 16) 1 1 1 0 0 2 = 1 C 16 Method: Starting from LSD, sector in group of four. Insert dummy 0’s when there is not enough For each group of four, calculate its decimal value, and it is be the digit for hexadecimal Example Convert 2 A 5 7 16 to binary 2 A 5 7 (base 16) 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 1 (base 2) 2 A 5 7 16 = 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 1 2 Method: Convert each digit into the binary representation of four digit
Hwa Chong Institution H2 Computing 5 5.3.4 Conversion between octal and other bases Although octal bases are excluded from the new syllabus, it is an interesting part to learn. Conversion between octal and binary is similar to the conversion between hexadecimal and binary. Example Convert 1 0 1 0 1 0 0 1 0 1 0 1 1 1 2 to octal By sectoring in group of three 0 1 0 1 0 1 0 0 1 0 1 0 1 1 1 (base 2) 2 5 1 2 7 (base 8) 1 0 1 0 1 0 0 1 0 1 0 1 1 1 2 = 2 5 1 2 7 8 Example Convert 7 0 1 5 8 to binary 7 0 1 5 (base 8) 1 1 1 0 0 0 0 0 1 1 0 1 (base 2) 7 0 1 5 8 = 1 1 1 0 0 0 0 0 1 1 0 1 2 However, the conversion between octal and hexadecimal uses binary as an intermediate step. Example Convert 2 A 5 7 16 to octal 2 A 5 7 (base 16) 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 1 1 1 (base 2) 0 2 5 1 2 7 (base 8) 2 A 5 7 16 = 2 5 1 2 7 8
Hwa Chong Institution H2 Computing 6 Tutorial 5A 1. Perform the following conversion between different bases: Binary 1010 Denary: Denary 27 Binary: Denary 63 Hexadecimal: Hexadecimal B48 Denary: Binary 10110 Hexadecimal: Hexadecimal FF60 Binary: 2. Write a non-recursive function, for each part, that converts (a) Binary numbers to decimal numbers (b) Decimal numbers to hexadecimal numbers (c) Hexadecimal numbers to binary numbers 3. Write a recursive function for decimal to binary conversion.
Hwa Chong Institution H2 Computing 7 5.4 Check Digit Recall in Section 1.5, we discussed many ways of data validation to ensure the correct input of data. Code numbers such as customer number, employee number or product number are often lengthy and prone to errors when being keyed in. One way of preventing these errors is to add a check digit to the end of the code number. The check digit is derived by applying some algorithm to the digits of the code number. In this way, the code number with its check digit is self-checking. Modulus 11 System Each digit of the code is assigned with a weight. The right hand digit is given a weight of 2, the next digit to the left is 3, and so on. (the check digit to be appended will have a weight of 1 ) Each digit is multiplied by its weight and the products are added together. The sum of the product is divided by 11 and the remainder is subtracted from 11 to give the check digit. As the check digit is a single digit, we have two special cases. If the remainder is 0 ,the check digit 1
Content continues in the PDF. Download PDF
Related notes
- NYJC 2026 Prelim P2Exam Papers · 2026
- NYJC 2026 Prelim P1Exam Papers · 2026
- DHS 2026 Y6 H2 Computing Prelim Paper 2_finalExam Papers · 2026
- ACJC 2026 JC2 Computing Prelim Paper 2 (Practical)Exam Papers · 2026
- 2026_NJC Prelim_Computing_P2.pdfExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P2_finalExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P1_markschemeExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P1_finalExam Papers · 2026
- 2026 ACJC Prelim Computing Paper 2Exam Papers · 2026
- 2024 ACJC Computing PromoExam Papers · 2024
- 2023 ACJC Promo QPExam Papers · 2023
- 2022 ACJC Computing Promo Paper 2Exam Papers · 2022
- See all H2 Computing notes

