Return to Video

https:/.../emt091080p.mp4

  • 0:18 - 0:22
    In this video I'm going to show
    you a different way of using
  • 0:22 - 0:25
    this complement notation pending
    on which method makes more
  • 0:25 - 0:29
    sense. Which method is easier
    for you? You've got the choice.
  • 0:29 - 0:33
    Doesn't matter which method you
    use, so just to recap why we're
  • 0:33 - 0:37
    doing the twos complement
    notation that this is one way to
  • 0:37 - 0:40
    represent negative numbers in
    the binary number system. And
  • 0:40 - 0:44
    again to recap, if the number
    starts with a zero in the twos
  • 0:44 - 0:48
    complement notation that we know
    that this is a positive number.
  • 0:48 - 0:54
    And if a number starts with N1,
    we know that this is a negative
  • 0:54 - 0:59
    number, so the 1st digit in the
    twos complement notation is used
  • 0:59 - 1:03
    for the sign bit. Therefore
    there's a limitation. So
  • 1:03 - 1:07
    depending on how many bits you
    using for this compliment
  • 1:07 - 1:12
    notation, we can only use one
    less bit for building the actual
  • 1:12 - 1:17
    numbers. So again, just to
    recap, in case you haven't seen
  • 1:17 - 1:19
    the previous video, every single
  • 1:19 - 1:23
    number. In the two complement
    notation have to be used at a
  • 1:23 - 1:27
    fixed length, so you can't talk
    about, just generally the twos
  • 1:27 - 1:31
    complement notation. You always
    have to say what length of bits
  • 1:31 - 1:35
    you talking about, so you can
    talk about the four bits twos
  • 1:35 - 1:39
    compliment. You can talk about
    the 7 bits this compliment, or
  • 1:39 - 1:44
    you can talk about the 22 bits
    2's complement, but you always
  • 1:44 - 1:47
    have to give whoever reads
    numbers the length, the fixed
  • 1:47 - 1:50
    length of the numbers. Otherwise
    the deuce complement notation.
  • 1:51 - 1:54
    It doesn't necessarily work, so
    this second method is slightly
  • 1:54 - 1:58
    different from the previous one,
    but the answers will be the
  • 1:58 - 2:03
    same. So in the previous method,
    we converted and then we kind of
  • 2:03 - 2:06
    inversion process. In this
    method we also using something
  • 2:06 - 2:08
    similar, so step one.
  • 2:09 - 2:11
    Again, we will be to convert.
  • 2:12 - 2:13
    Into binary.
  • 2:15 - 2:17
    But then Step 2.
  • 2:19 - 2:21
    Would be just a simple
    inversion.
  • 2:23 - 2:26
    So we don't have to do
    anything like copying bits
  • 2:26 - 2:30
    or whatever. We just invert
    all of the digits, but then
  • 2:30 - 2:32
    comes on next tab.
  • 2:33 - 2:35
    And that is odd.
  • 2:36 - 2:37
    1.
  • 2:38 - 2:41
    And I'm going to show you
    why this is working and how
  • 2:41 - 2:44
    we can do this, but let's
    look at an exact example.
  • 2:45 - 2:52
    So what would be negative four
    in four Bits 2's complement? OK,
  • 2:52 - 2:54
    so step one.
  • 2:57 - 3:01
    Convert so again, we're using 4
  • 3:01 - 3:01
    bits.
  • 3:02 - 3:08
    1248
    and four is just
  • 3:08 - 3:12
    100. And don't
    forget we need the
  • 3:12 - 3:13
    zero first here.
  • 3:14 - 3:15
    OK.
  • 3:16 - 3:20
    Then Step 2 is the invert.
  • 3:22 - 3:26
    So what happens here then
    everywhere I have got a zero, I
  • 3:26 - 3:31
    turn it into your one and
    everywhere when I have a one, I
  • 3:31 - 3:36
    turn it into a 0 so zero become
    one and one becomes zero. And
  • 3:36 - 3:38
    then comes the extra step.
  • 3:39 - 3:42
    Is the adding one so one?
  • 3:45 - 3:47
    1 + 1 makes 0.
  • 3:48 - 3:55
    Carry the one 1 + 1 makes
    0 carry the one 1 + 0
  • 3:55 - 4:00
    makes one and one plus
    nothing keeps one, so minus
  • 4:00 - 4:06
    four is the same as 1100 in
    4 bits 2's complement.
  • 4:07 - 4:13
    So let's look at minus six and
    again converted using the four
  • 4:13 - 4:16
    bits to complement, so step one
  • 4:16 - 4:22
    convert. So 4 bits on using
    1, two for an 8 and I know
  • 4:22 - 4:27
    that the six I will the
    negative six. I will be able
  • 4:27 - 4:31
    to show because it's less
    than 8, so six is 4 + 2.
  • 4:33 - 4:37
    And again I need the rest
    of the zeros and I need to
  • 4:37 - 4:41
    0 here as well because I'm
    talking about four bits 2's
  • 4:41 - 4:42
    complement, then Step 2.
  • 4:43 - 4:44
    Invert.
  • 4:46 - 4:49
    So zeros becomes ones
    and ones become zero.
  • 4:51 - 4:52
    And then the last step.
  • 4:54 - 5:01
    Is plus one so one comes here
    and I just need to add them
  • 5:01 - 5:09
    together. 1 + 1 makes 0 karida
    one 1 + 0 makes 1 zero plus
  • 5:09 - 5:16
    nothing is 01 plus nothing is 1,
    so minus six is the same as 1010
  • 5:16 - 5:22
    in 4 bits. This compliment now
    don't forget that this is not
  • 5:22 - 5:24
    the same as 1010.
  • 5:24 - 5:28
    Just as an ordinary binary
    number. So if you just look at
  • 5:28 - 5:32
    this from context, it needs to
    be cleared. If it's a compliment
  • 5:32 - 5:35
    notation, or if it's just
    ordinary binary notation,
  • 5:35 - 5:38
    because depending on the
    difference between complements
  • 5:38 - 5:42
    and ordinary numbers when you
    trying to convert it back into
  • 5:42 - 5:45
    to find out the decimal
    equivalent, you would do
  • 5:45 - 5:46
    different process is.
  • 5:48 - 5:53
    Let's look at another example.
    So what is 7 in five Bits 2's
  • 5:53 - 5:58
    complement notation? So 75 bits
    2's complement. Now this is a
  • 5:58 - 6:03
    positive number, so when it's a
    positive number I don't need to
  • 6:03 - 6:07
    do the inversion process. So
    again, just like in the
  • 6:07 - 6:11
    previous video, positive
    numbers are the easy examples
  • 6:11 - 6:16
    because all we need to do is
    just step one the conversion.
  • 6:19 - 6:24
    So the place values again, we're
    using that 5 bits, so make sure
  • 6:24 - 6:28
    that you using order 5 bits 124,
    eight, 16 that's all 12345 bits.
  • 6:28 - 6:34
    Then, which one of these do we
    need to be at? 7 again? 7 is 1
  • 6:34 - 6:39
    less than 8, so I will need to
    use every single digits that are
  • 6:39 - 6:45
    less than 8. So 1 + 2 + 4 makes
    7 altogether, but because it's 5
  • 6:45 - 6:49
    minutes to complement notation,
    I need to put the zeros in front
  • 6:49 - 6:57
    of it. So positive 7 is the
    same as 00111 in five bits,
  • 6:57 - 6:59
    this complement notation.
  • 7:02 - 7:08
    Now how can we do it the other
    way around? So let's say that
  • 7:08 - 7:14
    you are given a number 10011 and
    you are told that this is a 5
  • 7:14 - 7:16
    bits 2's complement notation
  • 7:16 - 7:20
    number. So how can we find
    out what number is this one
  • 7:20 - 7:23
    now? Remember that we went
    from when we went from
  • 7:23 - 7:26
    decimal to binary, viewed
    under conversion. Then we
  • 7:26 - 7:30
    done the inversion and then
    we done the odd one. So when
  • 7:30 - 7:33
    you've got the binary
    equivalent and you want to go
  • 7:33 - 7:37
    back to the decimal, then you
    have to do that step by step
  • 7:37 - 7:39
    going backwards. So the Step
    1 first here be.
  • 7:41 - 7:47
    Take away one. Let's do that
    now. So 10011 I need to take
  • 7:47 - 7:51
    away one. One takeaway one is
  • 7:51 - 7:56
    0. One takeaway, nothing is 1
    zero takeaway. Nothing is 00
  • 7:56 - 8:00
    takeaway, nothing is zero and
    one takeaway zero is 1 so
  • 8:00 - 8:04
    that is the first stage. Then
    remember that the middle step
  • 8:04 - 8:05
    was.
  • 8:07 - 8:12
    The inversion, So what I need to
    do now I need to invert this
  • 8:12 - 8:16
    number so zero becomes 11,
    becomes 00, becomes 10, becomes
  • 8:16 - 8:21
    one and one becomes zero, and
    this is the ordinary binary
  • 8:21 - 8:26
    equivalent of this 5 bits 2's
    complement an. Now what I can do
  • 8:26 - 8:28
    is do the last step.
  • 8:29 - 8:33
    Which in this case will be
    the conversion.
  • 8:34 - 8:37
    So just put the place values on
    top of the number.
  • 8:38 - 8:40
    8 + 4 + 1.
  • 8:42 - 8:47
    That makes 13, so this number is
    the equivalent is minus 13 OK
  • 8:47 - 8:51
    and we have done this conversion
    in the previous video, so you
  • 8:51 - 8:55
    can double check there and
    convince yourself that this is a
  • 8:55 - 8:57
    correct way of doing it.
  • 9:00 - 9:08
    So look at one more example
    01011. This is again A5 bits.
  • 9:09 - 9:11
    Two's complement notation.
  • 9:12 - 9:16
    Now again, this is a positive
    number because it starts with
  • 9:16 - 9:20
    zero, so therefore this number
    has not gone through the
  • 9:20 - 9:23
    inversion, and adding one
    process. So when I see a number
  • 9:23 - 9:27
    like this, I know it's going to
    be an easy calculation because
  • 9:27 - 9:32
    all I need to do is just one
    step and that is the conversion.
  • 9:35 - 9:38
    So how do I convert this
    number back to ordinary
  • 9:38 - 9:40
    binary? Let's just copy
    this one down here again.
  • 9:42 - 9:46
    And the easiest and quickest
    way, at least for me, is to put
  • 9:46 - 9:48
    the place values on top.
  • 9:50 - 9:56
    And then just add those numbers
    together. So 8 + 2 + 1 makes 11,
  • 9:56 - 9:58
    so this number is positive 11.
  • 10:02 - 10:06
    So let's look at a couple of
    eight bits to complement
  • 10:06 - 10:11
    examples because that is quite
    widely used. So how could we
  • 10:11 - 10:16
    represent minus? 94 in eight
    Bits 2's complement.
  • 10:17 - 10:22
    So remember step one good. It's
    a negative number. I need to go
  • 10:22 - 10:25
    through all three steps. Step
    one will be conversion.
  • 10:27 - 10:34
    So 8 bits 124
    eight 1630 two 64128,
  • 10:34 - 10:40
    so 12345678 different bits
    to represent my number.
  • 10:40 - 10:47
    So I need to
    build up 94 so.
  • 10:47 - 10:53
    64 I'm going to use and the
    difference between 94 and 64.
  • 10:54 - 10:58
    It's a handy 30, so the next
    step is how can I build up 30
  • 10:58 - 11:03
    from the rest of the digits? Now
    32 is too big because I'm only
  • 11:03 - 11:07
    need 30, so the next biggest
    place where you can use is 16,
  • 11:07 - 11:11
    so it takes 16 away from this
    and the remainder is 14.
  • 11:13 - 11:15
    I can take eight from the 14.
  • 11:16 - 11:21
    The remainder is 6 and six is 4
    + 2 even number, so I'm
  • 11:21 - 11:26
    expecting the last bit to be 0
    and it is because I'm not using
  • 11:26 - 11:30
    the one and again, don't forget
    that you always need to make
  • 11:30 - 11:34
    sure that if there are empty
    spaces before your number, you
  • 11:34 - 11:39
    need to fill that in with zeros
    to make sure that your number
  • 11:39 - 11:44
    is 8 bits long. OK, so that was
    first step, the Step 2 then was
  • 11:44 - 11:45
    the inversion.
  • 11:46 - 11:50
    So what we need to do now,
    invert every single bits to the
  • 11:50 - 11:53
    opposite, so zero become one,
    one becomes 0.
  • 11:57 - 12:01
    So zero becomes 11, becomes
    zero and zero become one.
  • 12:01 - 12:04
    This is the inverted number.
    But what happens now?
  • 12:07 - 12:12
    Is I need to add 1. OK,
    so let's just copy the
  • 12:12 - 12:13
    number down here again.
  • 12:17 - 12:19
    An other one to it.
  • 12:20 - 12:25
    1 + 1 is zero karida one 1 +
    0 is 1.
  • 12:26 - 12:29
    And from here on I don't
    need to add anything, so
  • 12:29 - 12:31
    I can just copy them.
  • 12:38 - 12:42
    So the edmister is binary
    equivalent of minus 94. Is this
  • 12:42 - 12:45
    number now? You might ask
    yourself a question that you
  • 12:45 - 12:49
    know when I'm adding binary
    numbers together, sometimes I do
  • 12:49 - 12:53
    have to do loads of carrying.
    And what happens if I carried
  • 12:53 - 12:58
    this number over? So what
    happens if I needed to add 1 to
  • 12:58 - 13:01
    it and then I need to carry it?
  • 13:01 - 13:04
    Well, that. Extra bit here would
    be called the overflow.
  • 13:08 - 13:11
    And what the computer does is
    just simply ignores it. So if
  • 13:11 - 13:14
    after the addition you end up
    with a 9 bits long number, all
  • 13:14 - 13:18
    you need to do is ignore the
    first bit and your answer will
  • 13:18 - 13:19
    be just that 8 bit.
  • 13:21 - 13:24
    I hope that you now understand
    how the Two's complement
  • 13:24 - 13:28
    notation works, and I encourage
    you to try out the practice
  • 13:28 - 13:32
    questions that will follow and
    you can check your work by
  • 13:32 - 13:36
    looking at the answers for this
    video. We will have two sets of
  • 13:36 - 13:39
    questions. Here are the
    first set.
  • 13:40 - 13:43
    This is the answer
    to the first set.
  • 13:49 - 13:51
    Here is the 2nd set.
  • 13:59 - 14:02
    And here are the answers to
    the second set.
Title:
https:/.../emt091080p.mp4
Video Language:
English
Duration:
14:31

English subtitles

Revisions