Lecture Slides 02

download Lecture Slides 02

of 15

Transcript of Lecture Slides 02

  • 8/19/2019 Lecture Slides 02

    1/36

    1

  • 8/19/2019 Lecture Slides 02

    2/362

  • 8/19/2019 Lecture Slides 02

    3/36

  • 8/19/2019 Lecture Slides 02

    4/36

    The topics that are covered in this lecture are different types of number systems.This includes decimal and binary, and methods to convert from one numbersystem to another.

  • 8/19/2019 Lecture Slides 02

    5/36

    This slide illustrates the binary to decimal conversion.

    A binary number can be converted to its decimal equivalent by adding theweights for each bit position that contains a 1.

    Positional values increase by a factor of 2 from LSB to MSB i.e., from right toleft by a power of 2. The LSB is the first bit and has a weight of 2 ^ 0, or 1. TheMSB has a weight of 2 ^ (N + 1), where N is the number of bits.

    In the first example, 1 multiplied by 2^0 is 1 . Then 1 multiplied by 2^1 is 2, 0multiplied by 2^2 is 0, and so on. There are 5 bits, so the MSB has a weight of 2^4 (or 16) . Similarly in the second example, the MSB is the eighth bit and has a weight of 2^ 7, or 128.

    Binary and decimal numbers are represented using a subscript of 2 (11011 2 ) and10 (27 10 ) respectively.

  • 8/19/2019 Lecture Slides 02

    6/36

    Here are some examples of the largest binary numbers that can be written using agiven number of bits.

  • 8/19/2019 Lecture Slides 02

    7/36

    This slide shows the largest decimal equivalent number for a given number of bits.

    One way to find this is to consider the value when all bits in the binary numberare 1. For example, the largest number that can be represented by three bits is111 2. Its decimal equivalent is 7 10 in decimal:

    (1 x 2 2 ) + ( 1 x 2 1 ) + ( 1 x 2 0 ) = 4 +2 + 1 = 7

    Another option is calculate the number of combinations possible. If there are 3 bits in the binary number, this allows 2 3 = 8 different combinations. Zero is oneof these, so the largest decimal number represented by a 3-bit binary number is(23-1) =(8-1)= 7 10.

    The largest decimal number represented by an 8-bit binary number is ( 2 8 – 1) =(256-1) =255 10

    With N bits, the largest decimal number is ( 2 N -1).

  • 8/19/2019 Lecture Slides 02

    8/36

    The smallest number we can represent with a binary number occurs when all bitsare zero. So the range of actual decimal numbers that can be represented is 0 to (2 N -1).

  • 8/19/2019 Lecture Slides 02

    9/36

    Another method of binary to decimal conversion that avoids addition of largenumbers is called the double dabble method . It also keeps track of the columnweight.

    This slide illustrates this method using the binary number 1101 12.

    The steps for conversion are as follows:

    1. First, write down the left-most 1 in the binary number.

    2. Double it and add the next bit on the right even if it is a 0.3. Write down the result under the next bit.

    4. Continue with steps 2 and 3 until finished with all bits in binarynumber.

  • 8/19/2019 Lecture Slides 02

    10/36

    For conversion from decimal to binary, the decimal number is expressed as a sumof powers of 2. Then 1s and 0s are written in the appropriate bit positions asrequired.

    In the first example here, 0 is placed in the 21 and 24 positions, because all positions must be accounted for.

  • 8/19/2019 Lecture Slides 02

    11/36

    Another method for converting decimal integers into binary uses repeateddivision by 2.

    This slide illustrates the conversion process for 25 10 to binary.

    It requires repeated division of the decimal number by 2 and writing down theremainder (1 or 0) after each division until a quotient of 0 is obtained.

    When the decimal number 25 is divided by 2, the quotient is 12 and remainder is1. This first remainder is the LSB.

    Similarly, in the final step, when 1 is divided by 2, the quotient is 0 andremainder is 1. This final remainder is the MSB.

  • 8/19/2019 Lecture Slides 02

    12/36

    This flowchart describes the repeated division method of conversion of decimalintegers to binary. The same process can be used to convert a decimal integer toany other number system.

  • 8/19/2019 Lecture Slides 02

    13/36

    Here is another example for decimal to binary conversion using repeateddivision.

    When the decimal number 37 is divided by 2, the quotient is 18 and remainder is1. This first remainder is the LSB. Note that the digit after the decimal pointmeans a remainder of 1.

    Similarly, in the final step, when 1 is divided by 2, the quotient is 0 andremainder is 1. This final remainder is the MSB.

  • 8/19/2019 Lecture Slides 02

    14/36

  • 8/19/2019 Lecture Slides 02

    15/36

  • 8/19/2019 Lecture Slides 02

    16/36

    Another useful number system is the hexadecimal number system.

    It uses a base of 16 and has 16 possible digit symbols. It uses the digits 0 throughto 9 and the letters A, B, C, D, E and F as the 16 symbols. Digits A through to Fare equivalent to the decimal values 10 through 15.

    Each hexadecimal digit represents a group of 4 binary bits. With 4 bits 2^4 or 16different numbers can be represented.

    In this number system, for digits to the left of the hexadecimal point, the weightsof each bit increase by a factor of 16 as one moves from right to left.

  • 8/19/2019 Lecture Slides 02

    17/36

    This slide shows the equivalent numbers in hexadecimal, decimal and binarynumber systems.

    Using 4 bits, we can represent decimal numbers from 0 to 15 10 and equivalenthexadecimal numbers from 0 to F.

  • 8/19/2019 Lecture Slides 02

    18/36

    A hexadecimal (or hex) number can be converted to its decimal equivalent bymultiplying each hex digit by its positional weight.

    Positional weight increases by a factor of 16 for each digit from the least to mostsignificant digit. The least significant digit (LSB) has a weight of 16 ^ 0, or 1.The next bit has a weight of 16^ 1, or 16. In the examples here there are 3 digits,and the most significant digit (MSB) is 16 ^ 2, or 256.

    In the first example, the most significant digit is 3 and the least significant digit is6. The number is 3 x 16^2 + 5 x 16^1 + 6 x 16^0 = 3 x 256 + 5 x 16 + 6 x 1 = 854

    in decimal.

    Hexadecimal numbers are represented using a subscript of 16 (356 16 ).

  • 8/19/2019 Lecture Slides 02

    19/36

    This slide describes the repeated division method for converting decimal integersinto hexadecimal number.

    Decimal to binary conversion was shown using repeated division by 2. Similarly,decimal to hexadecimal conversion can be done using repeated division by 16.

    It requires repeated division of the decimal number by 16 and writing down theremainder after each division until a quotient of 0 is obtained.

    The hexadecimal number is obtained by writing the first remainder as the LSB and the last remainder as MSB .

  • 8/19/2019 Lecture Slides 02

    20/36

    Here is an example of the conversion process for 423 10 into hex.

    At first when 423 is divided by 16, the quotient is 26 and remainder is 7. Thisfirst remainder is the LSB.

    Similarly in the final step, when 1 is divided by 16, the quotient is 0 andremainder is 1. This final remainder is the MSB.

    It should be noted that any remainders that are greater than 9 arerepresented by the letters A through F.

  • 8/19/2019 Lecture Slides 02

    21/36

    This slide describes another example of the conversion process for 214 10 intohex.

    At first when 214 is divided by 16, the quotient is 13 and remainder is 6. Thisfirst remainder is the LSB.

    Similarly in the final step, when 13 is divided by 16, the quotient is 0 andremainder is 13. This final remainder is the MSB.

    It is noted that digit 1310

    is represented by a letter D in hexadecimal.

  • 8/19/2019 Lecture Slides 02

    22/36

    It is possible to convert a number from hex to binary.

    Each hex digit is converted to its 4-bit binary equivalent.

    The binary equivalent of hexadecimal number 2 16 is 0010 2 . Note the leadingzeros that are added to the left of the MSB to complete a 4-bit group.

    Since 9 is 1001 in binary, F is 1111, and 2 is 0010, the resulting binary number is100111110010.

  • 8/19/2019 Lecture Slides 02

    23/36

    This slide describes the conversion method from binary to a hex equivalent.

    In this case, the binary number is grouped into groups of 4-bits starting with theLSB. Each group is then converted to the equivalent hexadecimal digit.

    The leading zeros are added to the left of the MSB to complete a 4-bit group.

  • 8/19/2019 Lecture Slides 02

    24/36

    This slide describes the conversion method from decimal to binary, by convertingto a hex number first. This can be an easier process than converting directly.

    At first the decimal number 378 10 is converted to hexadecimal using repeateddivision by 16 and then each hex digit is converted to its 4-bit binary equivalent.

    Now, 378 (base 10) = 17A (base 16) = 0001 0111 1010 (base 2) which is a 12 bit binary number.

    A 16 bit binary number is obtained by adding four leading zeros to the left of theMSB, so finally we have 0000 0001 0111 1010

  • 8/19/2019 Lecture Slides 02

    25/36

  • 8/19/2019 Lecture Slides 02

    26/36

    This slide shows counting in hex.

    When there is a 9 in a digit position, it becomes an A when it isincremented. For example 39 16 + 1 16 = 3A 16

    When there is a F in a digit position, it is reset to 0 when it is incremented

    by 1. a 1 is added to the digit on the left. For example 3F 16 + 1 16 = 40 16

  • 8/19/2019 Lecture Slides 02

    27/36

  • 8/19/2019 Lecture Slides 02

    28/36

  • 8/19/2019 Lecture Slides 02

    29/36

    Binary coded decimal (BCD) is not a number system on its own. It provides away to represent decimal numbers in binary, where each digit is encoded to its

    binary equivalent using four bits.

    The primary advantage of BCD is the relative ease of converting to and fromdecimal.

  • 8/19/2019 Lecture Slides 02

    30/36

    This slide describes the conversion method from decimal number to BCD.

    For the process, each decimal digit is converted to its 4-bit binary equivalent.

    Since the largest decimal digit is 9, BCD cannot represent a digit which ismore than 9.

  • 8/19/2019 Lecture Slides 02

    31/36

    For conversion from BCD to the equivalent decimal number, the BCD number isgrouped into groups of 4 bits starting with the LSB. Each group is then convertedto the equivalent decimal digit.

  • 8/19/2019 Lecture Slides 02

    32/36

    Since the largest decimal digit is 9, BCD cannot represent a digit which is greaterthan 9. The binary groups 1010 1111 are forbidden in BCD. Only 10 of the16 possible 4 bit binary code groups are used.

    In this example 1100 represents decimal equivalent 12, which is invalid inBCD representation.

  • 8/19/2019 Lecture Slides 02

    33/36

    This slide shows the representations of 0 10 to 15 10 using different numbersystems.

  • 8/19/2019 Lecture Slides 02

    34/36

    Most computers process and store information 8 bits at a time. 8 bits are referredto as 1 byte.

    Sometimes 8 bits are broken into 4 bits, known as a nibble, because hexadecimalnumbers are represented using 4 bits.

    Modern computers are often said to have 32-bit or 64-bit processors. This meansthat the word size of the computer is 32 or 64 bits and the computer can process32 or 64 bits of information at a time.

    Word size is variable from one computer to another.

  • 8/19/2019 Lecture Slides 02

    35/36

  • 8/19/2019 Lecture Slides 02

    36/36