0478 Computer Science
Chpater 1 Number System
1.1 Number systems
1.2 Text, sound and images
1.3 Data storage and compression
Chapter 2 Data transmission
2.1 Types and methods of data transmission
2.2 Methods of error detection
2.3 Encryption
Chapter 3 Hardware
3.1 Computer architecture
3.2 Input and output devices
3.3 Data storage
3.4 Network hardware
Chapter 4 Software
4.1 Types of software and interrupts
4.2 Types of programming language, translators and integrated development environments (IDEs)
Chapter 5 The internet and its uses
5.1 The internet and the World Wide Web (WWW)
5.2 Digital currency
5.3 Cyber security
Chapter 6 Automated and emerging technologies
6.1 Automated systems
6.2 Robotics
6.3 Artificial intelligence (AI)
Chapter 7 Algorithm design and problem solving
7.1 The program development life cycle
7.2 Computer systems, sub-systems anddecomposition
未命名
未命名
Chapter 8 Programming
8.1 Programming concepts
8.2 Arrays
Mr. Theo
-
+
首页
1.1 Number systems
# Data Representation ## Number Systems ### Binary System - Base 2 number system - It has two possible values only (0 and 1) - 0 represents OFF, and 1 represents ON - A point to be noted is that the most left bit is called the MSB (Most Significant Bit) #### Explain why the data is converted to binary by the computer - Computers use switches that only process the values 1 and 0 ### Denary System - Base 10 number system - Has values from 0 to 9 ### Hexadecimal (aka Hex) - Base 16 number system - Have values from 0 to 9 followed by A to F - A represents 10, B represents 11 and so on until 15, which is F | Similarities | Differences | | --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | - They are both number systems<br>- They both use the numbers 0 and 1 | − Binary is base-2 whereas hexadecimal is base-16<br>− Binary only uses 0 and 1 whereas hexadecimal uses 0 to 9 (and A to F)<br>− Hexadecimal uses letters but binary does not<br>− Hexadecimal needs to be converted to be processed, but binary does not | | Binary Value | Hexadecimal Value | Denary Value | | ------------ | ----------------- | ------------ | | 0000 | 0 | 0 | | 0001 | 1 | 1 | | 0010 | 2 | 2 | | 0011 | 3 | 3 | | 0100 | 4 | 4 | | 0101 | 5 | 5 | | 0110 | 6 | 6 | | 0111 | 7 | 7 | | 1000 | 8 | 8 | | 1001 | 9 | 9 | | 1010 | A | 10 | | 1011 | B | 11 | | 1100 | C | 12 | | 1101 | D | 13 | | 1110 | E | 14 | | 1111 | F | 15 | #### Why a computer can only process binary data - Computer consist of transistors / logic circuits/gates … - … that can only store/process data in two states / high-low / on-off / 1 and 0 ## Number Conversions ### Converting Binary to Denary - Place the binary value in columns of 2 raised to the power of the number of values from the right starting from 0. e.g. For binary value 11101110, place it in a table like this: | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:| | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | - As can be seen it starts from 1 and then goes to 128 from left to right - Now values with 1 are to be added together, giving the final answer, as for the example, it is 128 + 64 + 32 + 8 + 4 + 2 = 238 ### Converting Denary to Binary - Take the value and successively divide it by 2, creating a table like follows: | 2 | 142 | | | |:---:| --- | ---------- | --- | | 2 | 71 | Remainder: | 0 | | 2 | 35 | Remainder: | 1 | | 2 | 17 | Remainder: | 1 | | 2 | 8 | Remainder: | 1 | | 2 | 4 | Remainder: | 0 | | 2 | 2 | Remainder: | 0 | | 2 | 1 | Remainder: | 0 | | | 0 | Remainder: | 1 | - Note that when the value itself is not divisible by 2, it is divided by the previous value of the current number and 1 is added to the remainder column for that specific number - When you reach 0, the remainder has to be read from bottom to top giving us the binary value ( as in this case, it is 1 0 0 0 1 1 1 0 ) ### Converting Hexadecimal to Binary - Separate each value from each other and convert them to denary - Each separate denary value to be converted to binary - All the binary values to be merged together e.g. ```pseudocode Hexadecimal : 2 1 F D Denary : 2 1 15 13 Binary : 0010 0001 1111 1101 Final Answer: 0010000111111101 ``` ### Converting Binary to Hexadecimal - Divide the binary value into groups of 4 starting from the right. If at the end, the last division is less than 4, add 0s until it reaches 4 - For each group, find the denary value as shown above, and then convert each denary value to its corresponding hexadecimal value (if less than 10, then itself, else, 10 is A, 11 is B, 12 is C, 13 is D, 14 is E and 15 is F). - After conversion, just put all the hexadecimal values in order to get the final answer. ```pseudocode 1 0 0 0 0 1 1 1 1 1 1 1 0 1 ←Given Value 10 0001 1111 1101 ←When grouped 0010 0001 1111 1101 ←After 2 values added to left 2 1 15 13 ←After Conversion to Denary 2 1 F D ←Denary to Hexadecimal ``` ### Converting Hexadecimal to Denary - Convert the value to binary as shown above, and then convert the final answer to denary ### Converting Denary to Hexadecimal - Convert the value to binary, and then convert it to hexadecimal as explained above ## Binary Calculations - Binary values are not added the way denary values are added, as when adding 1 and 1, we cannot write two because it doesn’t exist in binary. ### Points to Note: - 0 + 0 = 0 - 1 + 0 / 0 + 1 = 1 - 1 + 1 = 0 (1 carry) - 1 + 1 + 1 = 1 (1 carry) ### Overflow - The value generated is larger than can be stored in the register - The result of the calculation would require more than 8 bits to be represented ### Steps to add Two Values (With Example) - The values we will add are 1 1 0 1 1 1 0 and 1 1 0 1 1 1 1 0 1. Convert both the bytes into 8 bits (add zero to the left-hand side to match them). e.g. 1 1 0 1 1 1 0 would become 0 1 1 0 1 1 1 0 2. Add the values as follows with the points given above ```pseudocode 0110 1110 + 1101 1110 ------------- 1 1111 11 ← carry values 1 0100 1100 ← sum values ``` **The solution would now be: (1) 0 1 0 0 1 1 0 0** ### Logical Shifts - The logical shift means moving a binary value to the left or the right - When doing a logical shift, keep in mind that the bit being emptied is going to become 0 ### Explanation with Example - **Shifting 10101010 - 1 place left:** 1. The furthest bit in the direction to be logically shifted is removed ( in this case, one at the LHS is removed) - ==(if it were two places, 2 bits would have been removed)== 2. Every bit is moved in given places to the given direction ( every bit is moved one place to the left in this case, and the leftover bit in the right is marked 0, so **10101010** would become **01010100**) ### Two’s Complement (Binary Numbers) - Two’s complement is a method used to represent negative values in binary. Here, the MSB ( Most Significant Bit) is replaced from 128 to -128; thus, the range of values in a two’s complement byte is -128 to 127 ### Converting Binary Values to Two’s Complement - Firstly, write the binary value and locate the first one from the right; e.g., 1101100 would have the first one at the third position from the right. - Now, switch every value to the left of the first one located above (not switching the one), e.g., the value in our example becomes 0010100, which is the two’s complement of itself. ### Converting negative values to two complement - Find the binary equivalent of the value ignoring the - sign - Convert the binary value to two’s complement - Make the MSB 1, if not already ### Converting Two’s Complement Value to Denary: - We do it the same way as a normal value is converted from binary to denary; we only replace 128 with -12,8 e.g., for 1011101,0 we do the: | -128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |:----:|:---:|:---:|:---:|:---:|:---:|:---:|:---:| | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | -128 + 32 + 16 + 8 + 2 = -70 ## Use of the Hexadecimal System #### Examples: - Hypertext Markup Language (HTML) colour codes - Media Access Control (MAC) addresses (a number that uniquely identifies a device on a network) - Display error codes (numbers refer to the memory location of the error) - IP (Internet Protocol) addresses ##### Mac Address - Media Access Control (address) - Used to identify a device - It is a unique (address) - It is a static address // It does not change - It is set by the manufacturer - The first part is the manufacturer ID/number/identifies the manufacturer - The second part is the serial number/ID ##### HTML - Hypertext Mark-up Language - Web authoring language // language used to write/create websites/web pages #### Why a programmer may use hexadecimal to represent binary numbers - Easier/quicker to understand/read/write - Easier/quicker to debug - Less likely to make a mistake - Shorter representation // Takes up less screen space #### Benefits, to users, of converting binary values to hexadecimal - Easier/quicker to read/write/understand - Easier/quicker to identify errors/debug - Takes up less screen/display space - Less chance of making an error #### Similarity between an IP address and a MAC address - Both addresses can be used to identify a computer/device Both are unique - Both can be represented as hexadecimal - Both addresses do not change if IP address is static #### Differences between an IP address and a MAC address - An IP address is assigned by the network/router/ISP, A MAC address is assigned by the manufacturer - An IP address can be changed (if dynamic), MAC address cannot be changed - IP address has 4/8 groups of values, MAC address has 6 groups/pairs of values - IP address is 32-bit/ 128-bit, MAC address is 48-bit - IP address does not contain serial number/manufacturer number, MAC address does - IP(v4) address is denary and MAC address is hexadecimal
Theo
2025年9月1日 20:30
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
Word文件
PDF文档
PDF文档(打印)
分享
链接
类型
密码
更新密码
有效期