[Part 1] Unit 2.2 - Binary Addition

MakkuZjAileron
16 Jan 201812:13

Summary

TLDRThis script delves into the fundamentals of binary number representation and manipulation in computers, focusing on addition. It explains how computers perform binary addition without converting to decimal, using concepts akin to elementary school arithmetic but adapted for binary digits. The script introduces the concepts of half and full adders, which are essential for constructing an arithmetic logic unit (ALU) capable of adding binary numbers. It also touches on the issue of overflow in binary addition and how it's handled in computer systems.

Takeaways

  • πŸ’» The unit focuses on manipulating numbers in computers, specifically addition, and understanding how this operation works in binary.
  • πŸ”’ Addition of numbers in binary is similar to addition in decimal, with the concept of carrying over when the sum exceeds the value that can be represented by a single digit.
  • πŸ’‘ The addition of binary numbers can be done directly without converting them to decimal, which is essential for computer operations.
  • πŸ” Understanding binary addition allows us to derive other operations like subtraction and comparison for free, once negative numbers are understood.
  • βš™οΈ Multiplication and division are more complex operations and are generally handled by software rather than hardware.
  • βž• The process of binary addition starts with adding the right-most digits and proceeds to the left, carrying over as necessary, similar to how we add decimal numbers.
  • πŸ”§ A 'half adder' is a basic circuit that adds two binary bits and produces a sum and a carry bit, which is the first step in building an adder.
  • βš™οΈ A 'full adder' extends the concept of the half adder by including a carry bit from a previous addition, allowing it to add three bits at once.
  • πŸ—οΈ To add larger binary numbers, multiple full adders (and possibly a half adder) are connected in sequence, creating a multi-bit adder circuit.
  • πŸ› οΈ The final goal is to construct a 16-bit adder, which takes two 16-bit binary numbers as input and produces their 16-bit sum as output.

Q & A

  • What is the primary focus of the unit on binary numbers?

    -The primary focus of the unit is to learn how to manipulate binary numbers, specifically how to add them, as this foundational operation will lead to understanding other arithmetic operations.

  • Why is addition of binary numbers important before moving on to other operations?

    -Addition is fundamental because once understood, it allows for the derivation of subtraction and comparison of numbers. It also forms the basis for more complex operations like multiplication and division, which can be handled in software.

  • How does a computer perform addition of binary numbers without converting to decimal?

    -A computer performs binary addition by directly manipulating the bits, using a process similar to decimal addition but adapted for binary, with rules for carrying over when the sum exceeds the binary digit capacity.

  • What is a half adder and what does it do?

    -A half adder is a digital circuit that takes two binary inputs and produces a sum and a carry output. It is used when there is no initial carry, and it performs the basic addition of two bits.

  • What is the difference between a half adder and a full adder?

    -A half adder adds two bits without considering any incoming carry, while a full adder also takes into account an additional carry input from a previous addition step, allowing it to add three bits in total.

  • What is the concept of overflow in binary addition?

    -Overflow occurs when the addition of two binary numbers produces a carry that extends beyond the available bit width, meaning the result cannot be fully represented within the given number of bits.

  • How does a computer handle overflow in binary addition?

    -Typically, the computer ignores the carry bit that does not fit into the word size, effectively performing a modulo 2^n operation where n is the word size, and the result is truncated after overflow.

  • What is the significance of implementing a half adder in learning to build an adder?

    -Implementing a half adder is the first step in learning to build an adder because it introduces the basic binary addition operation without the complexity of an additional carry input.

  • How can multiple full adders be used to create an adder for larger binary numbers?

    -Multiple full adders can be connected in series, with the carry output of one feeding into the carry input of the next, allowing for the addition of larger binary numbers bit by bit from least significant to most significant.

  • What is the final goal in the unit after learning to add binary numbers?

    -The final goal is to build a complete arithmetic logic unit (ALU), which includes the ability to add numbers but also requires additional logic to handle various arithmetic and logical operations.

  • Why are multiplication and division considered more complicated in binary arithmetic?

    -Multiplication and division are more complex because they involve larger numbers and multiple steps, which can be more efficiently handled by software rather than dedicated hardware circuitry.

Outlines

00:00

πŸ“š Binary Number Representation and Basic Operations

This paragraph introduces the concept of representing numbers in binary form within computers and emphasizes the importance of being able to manipulate these numbers. The focus is on addition, which is foundational to other operations. The speaker explains that understanding binary addition will lead to a natural grasp of other operations like subtraction and comparison, while multiplication and division are more complex and are typically handled by software. The process of adding binary numbers is likened to the elementary method of decimal addition, with the key difference being the direct handling of binary digits without conversion to decimal. The concept of overflow in binary addition is also introduced, explaining how computers handle situations where the result exceeds the word size by effectively ignoring the excess, thus performing a modulo operation relative to the word size.

05:01

πŸ›  Building Binary Adders: From Half to Full Adders

The second paragraph delves into the technical process of creating hardware capable of adding binary numbers. It begins by detailing the simple operation of adding two bits, which is achieved through a half adderβ€”a basic component that takes two binary inputs and produces a sum and carry output. The paragraph then moves on to the full adder, which is an extension of the half adder, capable of incorporating an additional carry input from a previous operation. The full adder is essential for handling the carry bits that result from adding bits in sequence. The speaker outlines a three-stage process for constructing an adder: starting with adding two bits, then three, and finally scaling up to handle any number of bits. The paragraph concludes with a description of how to implement a 16-bit adder using a series of full and half adders, which is a practical application of the concepts discussed.

10:04

πŸ” Implementing a 16-Bit Adder and Looking Ahead to ALU

The final paragraph provides a practical guide on implementing a 16-bit adder, which involves connecting multiple full adders and a half adder in a specific configuration. The speaker assures that the necessary HDL (Hardware Description Language) will be provided for this exercise. The paragraph also previews upcoming topics, such as the representation of negative numbers and the construction of an Arithmetic Logic Unit (ALU). The ALU is highlighted as a crucial component that builds upon the binary addition logic already discussed, with additional logic to handle a variety of arithmetic and logical operations. The anticipation is set for the integration of these concepts into a more complex system in the subsequent units.

Mindmap

Keywords

πŸ’‘Binary Numbers

Binary numbers are a base-2 numeral system used in digital electronics, where each digit is either a 0 or a 1, representing the two possible voltage states of a circuit. In the video, binary numbers are the fundamental way computers represent and manipulate numerical data, and the script discusses how to perform arithmetic operations on them, starting with addition.

πŸ’‘Manipulation

In the context of the video, manipulation refers to the arithmetic operations that can be performed on numbers, such as addition, subtraction, multiplication, and division. The script emphasizes that once the process of adding binary numbers is understood, other operations can be derived or simplified, highlighting the importance of addition as a foundational operation.

πŸ’‘Negative Numbers

The concept of negative numbers is crucial for a complete understanding of arithmetic in computing. The script mentions that once the representation of negative numbers is understood in the next unit, it will enable the understanding of subtraction and comparison of magnitudes between two numbers without additional complexity.

πŸ’‘Multiplication and Division

These are arithmetic operations that the script notes as being more complex in binary representation compared to addition and subtraction. The video explains that hardware implementations for multiplication and division are not typically built into computers, instead, these operations are handled by software, which can manage them through programming.

πŸ’‘Software

Software refers to the programs and applications that run on a computer, as opposed to hardware, which are the physical components. In the script, software is highlighted as a means to perform complex arithmetic operations like multiplication and division by writing programs, rather than relying on hardware circuits.

πŸ’‘Carry

In binary addition, as in decimal, a 'carry' occurs when the sum of two bits is greater than the maximum value that can be represented by a single bit (i.e., the sum of 1+1 in binary is 10, which requires a carry). The script explains the process of carrying over in binary addition as fundamental to understanding how computers perform this operation.

πŸ’‘Half Adder

A half adder is a digital circuit that performs addition on two single binary digits, producing a sum and a carry output. The script describes the half adder as the basic building block for binary addition, where it is used when there is no initial carry to consider.

πŸ’‘Full Adder

A full adder is an extension of the half adder, capable of adding three binary digits, including a carry-in from a previous addition. The script explains that the full adder is essential for handling the carry bits in binary addition, allowing for the addition of multi-bit binary numbers.

πŸ’‘Overflow

Overflow in computing occurs when a calculation produces a result that is greater than the maximum value that can be represented with the available number of bits. The script discusses how computer systems typically handle overflow by ignoring the excess carry, effectively performing a modulo operation on the word size.

πŸ’‘Arithmetic Logic Unit (ALU)

An ALU is a digital circuit that performs arithmetic and logic operations on binary numbers. The script mentions the ALU as the culmination of the lecture series, where the primary operation, addition, is combined with other logic functions to create a complete computational unit.

Highlights

Introduction to representing numbers in binary and the importance of manipulation for arithmetic operations.

Explanation of how understanding binary addition is fundamental to other operations like subtraction and comparison.

Multiplication and division are complex and are typically handled by software rather than hardware.

The process of adding binary numbers directly without converting to decimal, using second-grade arithmetic as a basis.

Binary addition basics: adding 1+0 and 0+0, and the introduction of the carry concept with 1+1.

Illustration of binary addition with examples, including the handling of carries.

The concept of overflow in binary addition and how computer systems handle it by ignoring the carry that exceeds word size.

Introduction to the half adder chip, which is fundamental in binary addition operations.

The role of the full adder in handling binary addition with a carry from a previous step.

Building a 16-bit adder by connecting multiple full adders and a half adder.

The significance of the HDL (Hardware Description Language) in designing and implementing binary adders.

Practical exercise for implementing a half adder and a full adder using HDL.

The construction of a complete arithmetic logic unit (ALU) with addition as its core operation.

The theoretical underpinning of binary addition as a module 2 to the width of the word size.

The practical implications of overflow in computer arithmetic and its effect on the results of operations.

The educational approach of building hardware incrementally from understanding binary addition of individual bits.

The transition from understanding binary addition to representing negative numbers and the implications for subtraction.

The culmination of the lecture series with the construction of an ALU and its significance in computer architecture.

Transcripts

play00:03

In the last unit, we saw how to represent numbers in computers using binary bits,

play00:07

but now we can represent numbers, that's an important thing.

play00:11

Now the whole point of representing something is if we want to manipulate it.

play00:14

What kind of manipulations do we want to do with bi, with numbers?

play00:18

Well we want to add them, subtract them, multiply them and so on.

play00:22

This is what we're going to learn how to do in this unit.

play00:25

Well, not all of them.

play00:26

What we will really be talking about is how to add.

play00:29

Once we do that we'll basically get the whole rest of the other operations

play00:34

almost for free.

play00:35

It turns out that once we understand how to represent negative numbers,

play00:39

which we will do in next unit, we will be able to get subtraction for free and

play00:43

to understand which of two numbers is greater for free.

play00:45

Multiplication and divisions are more complicated, but nicely enough,

play00:50

we can actually postpone them to software.

play00:52

We will not build in hardware any multiplication or division eh, circuitry.

play00:57

But rather, we will actually let software do it and

play01:00

things are much easier to do in software because you just have to

play01:03

write little programs rather than actually connect stupid little devices.

play01:07

So we get two sequences of binary numbers.

play01:10

How can we add them?

play01:12

Well one way we already know how to do, and that's going to be very easy.

play01:15

We convert them to decimal.

play01:17

We add the decimal numbers.

play01:18

That we know how to do from second grade.

play01:20

We get a decimal number.

play01:21

We convert it back to binary.

play01:23

That we just learned how to do.

play01:25

And we get the answer.

play01:26

This is great and fine, but of course that's not what a computer does.

play01:29

A computer doesn't know how to add decimal numbers

play01:32

without first converting them to binary numbers.

play01:34

So we need to figure out how to actually do the addition of binary numbers, and

play01:40

directly, without converting them to decimal.

play01:43

And how are we going to do that?

play01:44

As usual, everything I need to know I learned in second grade.

play01:48

So we need to go back to second grade.

play01:50

We need to add 5,783 plus another number.

play01:55

How do we do this kind of addition?

play01:56

What did we learn?

play01:58

Well, we start with the ones, with a right-most digit, and we add 3 plus 6,

play02:02

we get the 9 and we are all very happy with that.

play02:04

That's easy.

play02:05

But now what happens when we next, do the next digit and we have 8 plus 5?

play02:10

Well, 8 5, as 8 plus 5 is 13, and

play02:13

we cannot write 13 underneath the tens position because 13 is greater than 10.

play02:18

So we all learned this important and amazing trick of say, writing only 3 and

play02:23

having 1 as a carry to the 100s place.

play02:26

And then we know how to con, we can continue from there.

play02:29

And then we can con, add the 1 to the 7 and so on.

play02:32

And after we finish the left-most digit, we have the complete result.

play02:39

So, exactly the same thing we're going to do in binary numbers,

play02:42

only it's going to be much, much easier.

play02:45

So we take 1 plus 0, the right-most two digits, and we need to add them.

play02:50

And that's easy, 1 plus 0 is 1, we can write it down.

play02:53

If we have 0 plus 0, that's also going to be very easy.

play02:57

We can write them down.

play02:59

Now the first time we get into a problem is we have 1 plus 1.

play03:03

because 1 plus 1 is 2.

play03:05

2 is more than what we can write in a single digit, bit, Boolean bit.

play03:10

So we actually need to do the same kind of trick, write down 0 and

play03:14

carry the 1 to the next position.

play03:17

And now we can continue.

play03:18

We need to add 1 plus 0 plus 1.

play03:20

That's again, more than what we can write in a single bit because that's 2.

play03:24

So we write 0, we carry 1.

play03:26

Now we have 1 plus 1 plus 1.

play03:28

The answer is 3.

play03:30

So we write down 1, and we carry another 1.

play03:32

And that's how we continue, until we get the final solution, the final answer.

play03:37

And that's all there is to it.

play03:40

In, the rest of the unit we'll actually learn how to do this thing exactly,

play03:45

how to do this thing completely mechanically,

play03:47

in the sense of really understanding how every operation works in true, ter,

play03:51

terms of binary operations that we've learned so far.

play03:54

But the basic principle is extremely simple,

play03:56

just like we learned in second grade.

play03:58

Before we continue, there is one thing I want to take out of the way, and

play04:01

that is a question of overflow.

play04:03

Suppose that we were somehow unlucky and the, and

play04:06

the two left-most bits of our, the two numbers we were adding were 1.

play04:11

So what is the problem with that?

play04:12

The problem is that, that when we add them,

play04:15

we have a carry that needs to go to the left of the word size.

play04:18

And there is no place to carry,

play04:20

to put that carry bit because we finished our word size.

play04:23

So what would we do?

play04:25

Will we raise some warning or anything like that?

play04:28

Well, the answer is very simple.

play04:30

What is usually done in computer systems is nothing.

play04:33

We just ignore any carry bit that does not fit into the word.

play04:37

What does that mean, really?

play04:39

So if you try to look at it from a mathematical point of view, what it means

play04:43

is that the addition that we're actually doing in our hardware is not real integer

play04:48

addition, because we cannot go beyond the numbers that fit inside the word size.

play04:53

Instead, what we have is really an addition module 2 to the width

play04:57

of the word size if you look at it mathematically.

play05:01

In others, in, in other, in other words, the answer is correct, but may, except for

play05:06

the case that it may be off by exactly 2 to the n where n is the word size.

play05:12

If the result was more than 2 to the n,

play05:14

the hardware automatically decreases 2 to the n,

play05:17

which is basically the carry that we just threw because there was an overflow.

play05:22

So that's what they usually do, and

play05:25

the rest of anyone using a computer, anyone using computer and software,

play05:29

needs to remember that if he exceeds the word size, then the result that you get,

play05:35

that you get is not the true integer result of the integer addition, but

play05:40

rather the truncated result after the overflow was already disposed of.

play05:45

Once we took good, got that out of the way, let's go back and

play05:48

try to understand how will we, we actually going to build this kind of an adder.

play05:54

How can we actually get, build hardware that gets two numbers as bits,

play05:59

as input bits, and the output is another number

play06:03

that actually represents the sum of the two input numbers?

play06:06

We'll do that in three easy stages.

play06:09

In the first stage we'll just learn how to add two bits.

play06:12

Very simple.

play06:14

The second stage we'll learn how to add three bits.

play06:17

It may seem there is a long way to go if we are progressing so slowly, but

play06:21

then in one big step we'll be able to add any two numbers of any number of digits.

play06:26

So let's start with that.

play06:28

So let's look at the typical operation we were,

play06:30

when we were adding two bits in the, in the process we just looked at.

play06:35

How do we took a 1 plus 1 and we added it and we got a 0 sum and a 1 carry.

play06:41

How did we do that?

play06:42

Well, the fir, most important thing is to notice that

play06:46

if the rest of the bits of all these two numbers do not add,

play06:50

do not matter at all when we're doing just this one bit slice of operation.

play06:54

Whatever the other bits were, as long as what we're adding now is 1 plus 1,

play06:59

and as long as one additional important thing, the carry so

play07:02

far, the carry we had to this place was 0,

play07:06

whatever the other bits are, we still are doing the operation exactly the same.

play07:11

We're going to put, write 0 below these two 1s,

play07:13

and we're going to have a carry of 1.

play07:16

This tells us that now we have really a just a simple binary operation.

play07:20

Taking two bits, a and b, and producing two output bits which depend

play07:25

only on them, which is one of them we're going to call the sum,

play07:28

the binary sum of these two things, and the other is a carry.

play07:32

And this is really the first step that we need to do.

play07:34

This would actually allow us to add two bits.

play07:38

Now this operation really, which is the slice one oper, one, one

play07:42

step of the process that we saw so far, is that's naturally abstracted by a chip.

play07:49

[COUGH] And the chip gets two inputs, a and b, two outputs, and we know exactly,

play07:52

for every combination of inputs, what the output is supposed to be.

play07:56

This chip is called the half adder, and

play07:59

implementing it is the first thing that you'll do in the exercise for this week.

play08:04

In fact, we're going to give you the exact HDL that describes the interface

play08:09

of this chip, and you're just going to have to do the implementation, which

play08:13

actually does implement this operation that we'll now understand what it is.

play08:18

And we've finished the first step of our journey adding,

play08:20

of journey to add numbers adding two bits.

play08:23

Now if you remember, the only real restrictions that we had when,

play08:27

when we were doing this addition of two bits was the fact that the carry to this

play08:31

point was 0.

play08:32

But that's not the general case.

play08:34

What happens more generally, is there may be a carry.

play08:37

Suppose now that we get another bit of the input, called c,

play08:40

which describes the carry from the previous step, which can be either 0 or 1.

play08:46

Now how do we do this addition?

play08:48

Well, we know we end, add the three numbers and

play08:50

we still get the sum and the carry.

play08:52

Again, now we get a Boolean gate, a chip,

play08:54

if you wish, that we know exactly its functionality.

play08:58

We have three inputs, a, b, and c, two outputs, sum and carry.

play09:03

And there are eight possibilities of the inputs.

play09:05

And for each of them, we can very well know what the outputs are.

play09:08

So that's another chip.

play09:09

And that chip is called a full adder.

play09:12

And again, you can go and implement it.

play09:15

And indeed, this is the second part of we, of our joining to addition.

play09:19

And again, we're giving you the HDL of this chip, and

play09:22

please go ahead and implement it.

play09:26

And now we're ready for the final step for doing everything.

play09:29

We get two full numbers and we want to add them.

play09:33

How are we going to do that?

play09:35

Well, we already know how to do every single step of the process, so

play09:39

we just have to repeat doing the single step.

play09:42

So let's look at what we did.

play09:43

We first, let's color the bits, the right-most bit yellow,

play09:48

the next one green, the next one blue.

play09:49

This is just so we can talk about them in terms of colors.

play09:53

But of course in the implementation there are no colors, just different bits.

play09:57

So we start of course, by just adding the two yellow bits.

play10:00

And adding the two yellow bits is just a half adder because we have no

play10:03

carry so far.

play10:04

And we get a yellow sum and a yellow carry.

play10:07

Now the next step is, we need to add the yellow carry to the two green bits.

play10:13

And from that, we get a green sum and a green carry.

play10:16

Now we take the green carry, add it to the two blue bits.

play10:21

Each one of these colored steps is simply a full adder now.

play10:24

The thing that takes that yellow carry, the two green bits, and

play10:28

outputs a green carry and a green sum, that's just a full adder.

play10:32

And that already we've implemented.

play10:34

So to implement the whole thing, we just need to basically connect 16 of

play10:38

these full adders, or maybe 15 full adders and 1 half adder for the right-most bit,

play10:43

connect them together in the right way, and you get exactly a, an adder.

play10:48

And this is what you're supposed to do.

play10:50

This is our 16-bit adder.

play10:52

It accepts two numbers now, each one of them is a bus of 16 bits, and

play10:58

outputs a single number that is supposed to be their sum as 16-bit integers.

play11:04

And again, we're going to give you the HDL for this.

play11:06

It just specifies that you're going to get two numbers, two 16-bit numbers,

play11:11

as busses in input, and produce a single number,

play11:15

16-bit bus as output that is their sum in terms of 2 representation of the number.

play11:23

And you can go ahead and implement that.

play11:26

So we've just learned how to add two numbers

play11:29

in a very concrete sense of building the chips that actually do that.

play11:33

The next unit we'll actually go back and actually look at how do we represent

play11:38

negative numbers, something that we still owe you from last unit.

play11:42

Once we do that it will turn out that we'll get subtraction for free.

play11:46

After we get that under our belt, then we'll go to the capstone of this week's

play11:52

this week's lecture which is building a complete arithmetical logic unit.

play11:57

And it turns out that most of the cleverness is already done.

play12:01

The most clever thing that we have in a ALU unit is just adding two numbers.

play12:06

But, of course, we need a lot of logic around it, and

play12:09

that's what we will do in the fourth unit.

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Binary NumbersComputer ArithmeticAddition PrinciplesCarry MechanismOverflow IssuesHardware ImplementationHalf AdderFull AdderBit ManipulationEducational ScriptDigital Logic