Lec 4 2025 PDF - Number Systems Conversions

Document Details

AthleticThallium

Uploaded by AthleticThallium

Misr University for Science and Technology

2025

Dr Mohamed Badawy

Tags

number systems binary decimal computer science

Summary

This document is a lecture on number systems, covering conversions between binary, decimal, and hexadecimal. Various techniques for conversion, calculation and representations. The content includes examples illustrating the conversion processes and arithmetic operations.

Full Transcript

2 Presented by: Dr Mohamed Badawy Base 16 Base 2 Used in Machine code Base 10 Used in Memory addresses...

2 Presented by: Dr Mohamed Badawy Base 16 Base 2 Used in Machine code Base 10 Used in Memory addresses Main system in computers Common in daily usage Used in Colours Hex Numbers can have upto 15 digits in one place: 0->9 and A -> F, where A = 10, B = 11... F=15 Base 8 Not commonly used N N/2 N%2 0101101 0 0 1 0 1 1 0 1 45 22 1 x x x x x x x x 7 6 5 4 3 2 1 0 22 11 0 2 2 2 2 2 2 2 2 11 5 1 32 + 8 + 4 + 1 = 5 2 1 45 2 1 0 1 0 1 0 0 0 0 0 1 0 1 1 0 1 2 D x x x x x x x x 3 2 1 0 3 2 1 0 2 2 2 2 2 2 2 2 0 0 1 0 1 1 0 1 2 1 + 4 + 8 = 13 = D 0 0 1 0 1 1 0 1 2 D 0 0 1 1 0 1 1 5 x x x x x x 2 1 0 2 1 0 2 2 2 2 2 2 001 101 1 5 001 101 15 45 -45 45 -45 0 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 1 01 00 10 Two representations of 0: 00000000 and 10000000 Two representations of 0: 00000000 and 11111111 Bad Arithmetic: Addition to negative number is not the same as subtraction. Arithmetic Works fine in this case: carry 1 1 1 1 : 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 01 00 10 1 1 0 1 1 0 1 0 != 00000000 1 1 1 1 1 1 1 1=0 To get 2's complement, you get 1's complement then add 1 45 -45 0 0 1 0 1 1 0 1 1 1 01 00 10 + 1 1 1 01 00 1 1 Quick Trick: starting from right to left, keep putting the zeros till you find a 1, put it, then flip the rest of the bits. e.g: 2's complement of 01001 100 = 10110 100 and 00001011 = 11110101 2's complement give unique representation to 0 and reserves common arithmetic (addition to negative value gives the same result as subtraction.) N N/2 N%2 010 0 0 1 0. 1 1 0 1 2 1 0 x x x x x x x x ans: 010.11010 1 0 1 3 2 1 0 -1 -2 -3 -4 2 2 22 2 2 2 2 0 0 0 decimal(N) N*2 Unit 11010 2 + 1/2 + 1/4 + 1/16 = 0.8125 1.625 1 2.8125 0.625 1.25 1 0.25 0.5 0 0.5 1.0 1 0 0 0 2.8125 = 2 + 0.8125 The Past Method cannot represent all numbers exactly. Some numbers require an infinite amount of bits to be exact. Exactly as we did with Hexa, but with Decimals 33.34 4 = 0100 3 = 0011 33.34 = 00110011. 00110100 BCD Requires Much space for long digits. 0 0 0 0 0 00 0. 1 1 0 0 1 0 1 1 This is clearly wrong! The issue is in adding 7 and 4. It gives a number > 9, which is not a valid digit (i.e. 1011 has no meaning under BCD) If you produce a digit greater than 9 (1001), add 6 (0110) then continue with regular addition. 0 0 0 0 0 00 0. 1 1 0 0 1 0 1 1 +0 1 1 0 Carry yellow bit to next 10 0 0 1 addition 0 0 0 0 0 00 0. 1 1 0 0 0 0 0 1 + 1 1 1 0 1 > 1 00 1 Add 0110 Again + 0 1 1 0 Carry yellow bit to next addition 1 00 1 1 0 0 0 0 0 00 0. 00 1 1 0 0 0 1 +1 Final Binary : 0 0 0 0 0 0 0 1. 0 0 1 1 0 0 0 1 Final Denary : 0 1. 31 = 0.37 + 0.94 We represent numbers in scientific notation We represent numbers in binary floating-point The units digit must be between 0 and 9 The units bit can either be 0 or 1 You multiply the value by 10 riased to the power The units bit if 1 indicated -1, if 0 indicates 0 of some number 1 e.g.: 11.25 = 1.125 x 10 Two separate bit groups: Mantissa and Exponent E General Form: N = m x 10 Mantissa is the base value (equivalent to 1.125 in the denary case) E Exponent: The number to raise 2 to (e.g. 2 ) Represent the numbers before and after the decimal point separately as before. Combine the two number together placing the decimal place after the first number. count the number of bits you had to move; this gives you the exponent value. Represent the exponent value in binary. This is called Mantissa-Exponent form. (Mantissa is the base value that you multiply by 2 ) 11.25 11 +.25 01011.010 0.1011010 Notice shifting of decimal place : 4 N N/2 N%2 places 11 5 1 Due to 4 places shift, E = 4 = 5 2 1 dec(N) N*2 units 0100 2 1 0 0.25 0.5 0 1 0 1 0.5 1.0 1 0 0 0 0 0 0 M= E = 00000100 0.1011010 To apply them on more than 1 bit, you apply the operation sequentially (bit by bit) Operation And OR Not both bits 1 when any bit is 1 bit is 0 are 1 both bits 0 when any bit is 0 bit is 1 are 0 Symbols &. | + ! ~ And (Multiplication) Or (Addition) Not (Negation) A B Output A B Output A Output 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 1 1 1 Left Shift Shifts all bits to the left by certain amount, add 0s to the beginning Symbol is > N, where N is number of place shifts e.g. 0010 1101 >> 2 => 0000 1011 (shift 2 places right) Circular Left Shift Shifts all bits to the left by certain amount, rotate the remaining bits from the begenning to the end e.g. 0110 1101 >c 2 => 0100 1011 (shift 2 places right) Float Number Systems Binary Regular: BCD Mantissa-Exponent Hex: base 16 binary: base 2 denary: base Convert as Regular. Extend to -ve power of Each digit takes 4 bits 0 -> 9; A -> F 0 -> 1 10 2 shift the point till before last bit. in addition: 0 -> 9 int part same as before ⚬ if > 1001: add 0110 This is your mantissa. dec part: Count the number of shifts ⚬ mult 2, ⚬ else: use as is. Represent this number in binary ⚬ record units place. Conversion ⚬ read top to bottom. This is your exponent Separate, then Every Multiply bit by digit 2^position to four bits then add He Binary Denary Logical x Every four bits Divide by 2 and record to digit, then remainder Operations combine stop when you reach 0 Read bottom to top. And Or Not Negative Binary 1 if both are 1 if either is 1 1 if 0 0 otherwise 1 0 otherwise 0 otherwise (circular) left shift (circular) right shift Move bits left Move bits right Sign bit: 1's complement 2's complement: (add bits to other (add bits to other last bit indicated flip all bits. end) end) flip all bits and add 1 sign good arithmetic good arithmetic Bad Arithmetic. non-unique 0 non-unique 0. unique 0

Use Quizgecko on...
Browser
Browser