🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

103-Fundamentals of Computer Unit-2 UNIT – 2 Computer Codes and Conversions 2.1 Computer Codes 2.1.1 Introduction to Computer Codes 2.1.2 Decimal System 2.1.3 Binary System 2.1.4 Hexadecimal System 2.1.5 Octal System 2.1.6 4-bit BCD S...

103-Fundamentals of Computer Unit-2 UNIT – 2 Computer Codes and Conversions 2.1 Computer Codes 2.1.1 Introduction to Computer Codes 2.1.2 Decimal System 2.1.3 Binary System 2.1.4 Hexadecimal System 2.1.5 Octal System 2.1.6 4-bit BCD System 2.1.7 8-bit BCD System 2.1.8 ASCII code 2.1.9 16-bit Unicode 2.2 Conversion of Numbers (from one Number System to another – includes fixed and fraction numbers) 2.1.1 Introduction to Computer Codes Computer codes are instructions written in programming languages that tell a computer what tasks to perform. These instructions form the basis of software applications, enabling computers to execute a wide variety of tasks, from simple calculations to complex operations like data processing, web browsing, and gaming. Types of Computer Codes 1. Machine Code 2. Assembly Language 3. High-Level Languages 4. Scripting Languages 5. Markup Languages Page 1 103-Fundamentals of Computer Unit-2 2.1.2 Decimal System Decimal system, also known as the base-10 numeral system, is a positional number system that uses ten distinct digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. It is the most commonly used numeral system for representing numbers in everyday life, mathematics, science, and commerce. The system operates on powers of ten, meaning that the value of each digit in a number depends on its position (or place) relative to the decimal point. Example: (24.5)10 = 2 × 101 + 4 × 100 + 5 × 10-1 2.1.3 Binary System The binary system, also known as the base-2 numeral system, is a method of numerical representation that uses only two digits: 0 and 1. It is the foundational system for modern digital computers and electronic systems, where these two digits correspond to the two states of electrical signals: off (0) and on (1). In binary, each digit's place value is a power of two, and its simplicity makes it ideal for computers to perform calculations and process data efficiently. Page 2 103-Fundamentals of Computer Unit-2 Binary to Decimal Conversion Example: (10101)2 = (1 × 24) + (0 × 23) + (1 × 22) + (0 × 21) + (1 × 20) = (21)10 Decimal to Binary Conversion Example: 2.1.4 Hexadecimal System Hexadecimal is a number system combining “hexa” for 6 and “deci” for 10. The hexadecimal system, also known as the base-16 numeral system, is a positional numeral system that uses sixteen distinct symbols to represent values. These symbols include the numbers 0 through 9 and the letters A through F. The letters A to F represent the decimal values 10 to 15. The hexadecimal system is particularly useful in computing and digital electronics because it provides a more human-readable representation of binary data. Hexadecimal to Decimal Conversion Example: (A7B)16 =(A × 162) + (7 × 161) +( B × 160) = (10 × 256) +( 7 × 16) +( 11 × 1) = 2560 + 112+ 11 (A7B)16 = 2683 Page 3 103-Fundamentals of Computer Unit-2 Decimal to Hexadecimal Conversion 2.1.5 Octal System The octal system, also known as the base-8 numeral system, is a positional numeral system that uses eight distinct digits to represent numbers. These digits are 0, 1, 2, 3, 4, 5, 6, and 7. The octal system is used primarily in computing and digital electronics as a more compact representation of binary numbers, making data easier to read and manipulate for human users. Octal to Decimal Numbers Example: 1238 = (1 × 82) + (2 × 81) + (3 × 80) = (1 × 64) +( 2 × 8) +( 3 × 1) = 64 + 16 + 3 = (83)10 Decimal to Octal Number Example: Page 4 103-Fundamentals of Computer Unit-2 2.1.6 4-bit BCD System Binary-Coded Decimal (BCD): A binary-encoded representation of integer values that uses a 4- bit binary number to represent each digit of a decimal number. 4-bit Representation: Each decimal digit (0-9) is represented by a 4-bit binary number. DECIMAL NUMBER BCD 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 Example: Let's represent the decimal number 593 using a 4-bit BCD system: 5 in BCD: 0101 9 in BCD: 1001 3 in BCD: 0011 So, 593 is represented in BCD as: BCD=0101 1001 0011 2.1.7 8-bit BCD System An 8-bit BCD (Binary-Coded Decimal) system is a digital encoding technique where each decimal digit is represented by an 8-bit binary number. This system is an extension of the more common 4-bit BCD system, allowing for more flexibility and greater precision in representing numbers. In an 8-bit BCD system, each byte (8 bits) represents a single decimal digit, typically using the lower 4 bits for the actual digit and the upper 4 bits for additional information, such as sign or special codes. Page 5 103-Fundamentals of Computer Unit-2 Example: Number 85 To represent the number 85 in an 8-bit BCD system: 8 is represented as 0000 1000. 5 is represented as 0000 0101. So, the number 85 in 8-bit BCD is: BCD=0000 1000 0000 0101 2.1.8 ASCII code ASCII (American Standard Code for Information Interchange) is a character encoding standard that uses numerical codes to represent text characters, punctuation marks, and control codes in computers and other devices that handle text. The ASCII code is widely used because of its simplicity and ease of implementation, making it a foundational component of modern computing systems. ASCII defines codes for 128 characters, which include: 1. Control Characters (0-31 and 127): Non-printable characters used to control text presentation. 2. Printable Characters (32-126): Letters, digits, punctuation marks, and a few special symbols. 3. Extended ASCII characters (128-255): Dagger, Double dagger, Bullet Page 6 103-Fundamentals of Computer Unit-2 2.1.9 16-bit Unicode UNICODE Unicode is a universal character encoding standard. This standard includes roughly 100000 characters to represent characters of different languages. While ASCII uses only 1 byte the Unicode uses 4 bytes to represent characters. Hence, it provides a very wide variety of encoding. It has three types namely UTF-8, UTF-16, UTF-32. Among them, UTF-8 is used mostly it is also the default encoding for many programming languages. UTF The UTF is the most important part of this encoding scheme. It stands for Unicode Transformation Format. Moreover, this defines how the code represents Unicode. UTF-16 It is an extension of UCS-2 encoding. Moreover, it uses to represent the 65536 characters. Moreover, it also supports 4 bytes for additional characters. Furthermore, it is used for internal processing like in java, Microsoft windows, etc. Page 7 103-Fundamentals of Computer Unit-2 Example: 2.2 Conversion of Numbers (from one Number System to another – includes fixed and fraction numbers) 1. Binary to Decimal 2. Decimal to Binary 3. Binary to Octal 4. Octal to Binary 5. Binary to Hexadecimal 6. Hexadecimal to Binary 7. Decimal to Octal 8. Octal to Decimal 9. Decimal to Hexadecimal 10. Hexadecimal to Decimal 11. Octal to Hexadecimal 12. Hexadecimal to Octal 1. Binary to Decimal Conversion Example: (1010.01)2 = 1x23 + 0x22+ 1x21 + 0x20+ 0x2-1 + 1x2-2 = 8 + 0 + 2 + 0 + 0 + 0.25 = (10.25)10 Page 8 103-Fundamentals of Computer Unit-2 2. Decimal to Binary Conversion Example: (10.25)10 Answer: (10.25)10 = (1010.01)2 3. Binary to Octal Conversion Example:10111011001.110101 Group the binary digits in sets of three, starting from the binary point. = 010 111 011 001. 110 101 = 0X22 + 1X21 + 0X20 1X22 + 1X21 + 1X20 0X22 + 1X21 + 1X20 0X22 + 0X21 + 1X20. 1X22 + 1X21 + 0X20 1X22 + 0X21 + 1X20 = 0+2+0 4+2+1 0+2+1 0+0+1. 4+2+0 4+0+1 = 2731.65 Answer: (10111011001.110101)2= (2731.65)8 4. Octal to BinaryConversion Example: 3.572 Convert each octal digit to its 3-bit binary equivalent. = 3 2 3 1 1 3 = 011 Page 9 103-Fundamentals of Computer Unit-2 =5 2 5 1 2 2 0 1 5 = 101 =7 2 7 1 2 3 1 1 7 = 111 =2 2 2 0 1 2 = 010 Combine the binary groups. Answer: (3.572)8= (011.101111101)2 5. Binary to Hexadecimal Conversion Example: 1101011.1010 Group the binary digits in sets of four, starting from the binary point. = 0110 1011. 1010 = 0x23 + 1x22 + 1x21 + 0x20 1x23 + 0x22 + 1x21 + 1x20. 1x23 + 0x22 + 1x21 + 0x20 =0+4+2+0 8+0+2+1.8+0+2+0 = 6B.A Answer:(1101011.1010)2= (6B.A)16 6. Hexadecimal to Binary Conversion Example:2F.A Convert each hexadecimal digit to its 4-bit binary equivalent. 2 2 0 1 = 2 -> 0010 Page 10 103-Fundamentals of Computer Unit-2 2 15 1 2 7 1 2 3 1 1 = F -> 1111 2 10 0 2 5 1 2 2 0 1 = A -> 1010 Answer:(2F.A)16= (00101111.1010)2 7. Decimal to Octal Conversion Example: (19.35)10 8 19 3 2 (19)10 = (23)8 Fraction part 0.35 x 8 = 2.80 0.80 x 8 = 6.40 0.40 x 8 = 3.20 0.20 × 8 = 1.60 Answer: (19.35)10= (23.2631)8 8. Octal to Decimal Conversion Example: (12.2)8 = 1x81 + 2x80+ 2x8-1 = 8 + 2 + 0.25 = 10.25 Answer: (12.2)8 = (10.25)10 9. Decimal to HexadecimalConversion Example:(47.6875)10 Page 11 103-Fundamentals of Computer Unit-2 = 47 16 47 15 2 47 = 2F = 0.6875 x 16 = 11 => B Answer: (47.6875)10= (2F.B)16 10. Hexadecimal to DecimalConversion Example: (1A.4F)16 = 1 x 161 + 10 x 160. 4 x 16-1 + 15 x 16-2 = 16 + 10. 0.25 + 0.05859375 = 26.30859375 Answer:(1A.4F)16 = (26.30859375)10 11. Octal to HexadecimalConversion Example: (32.45)8 Convert each digit of the hexadecimal number to its 3-bit binary equivalent. =3 2 3 1 1 = 3 => 011 =2 2 2 0 1 = 2 => 010 =4 2 4 0 2 2 0 1 = 4 => 100 =5 2 5 1 2 2 0 1 = 5 => 101 = 32.45 => 011 010. 100 101 Group the Binary Number into Sets of Four (from right to left for the integer and left torightfor the fractional parts) = 0001 1010. 1001 0100 Page 12 103-Fundamentals of Computer Unit-2 = 0x23 + 0x22 + 0x21 + 1x20 1x23 + 0x22 + 1x21 + 0x20. 1x23 + 0x22 + 0x21 + 1x20 0x22 + 1x22 + 0x21 + 0x20 = 0+0+0+1 8+0+2+0. 8+0+0+1 0+4+0+0 = 1A.94 Answer: (32.45)8= (1A.94)16 12. Hexadecimal to OctalConversion Example:1A.4C Convert each digit of the hexadecimal number to its 4-bit binary equivalent. =1 2 1 = 1 => 0001 = A => 10 2 10 0 2 5 1 2 2 0 1 = A => 1010 =4 2 4 0 2 2 0 1 = 4 => 0100 = C => 12 2 12 0 2 6 0 2 3 1 1 = C => 1100 = 0001 1010. 0100 1100 Group the Binary Number into Sets of Three (from right to left for the integer and left torightfor the fractional parts) = 000 011 010. 010 011 000 = 032.230 Answer: (1A.4C)16 = (032.230)8 Page 13

Use Quizgecko on...
Browser
Browser