0% found this document useful (0 votes)
73 views

Binary Notes

Unit 6 discusses binary numbers and how computers use binary to represent data. It explains that binary uses only two digits, 1 and 0, to represent all numbers and characters. Individual bits make up nibbles (4 bits) and bytes (8 bits). Multiple bytes then form larger units like 16-bit and 32-bit words that can represent larger numeric values. The document provides examples of how binary numbers are converted to their decimal equivalents by assigning place values to each bit based on powers of two. It also introduces hexadecimal as a base-16 numbering system used by computers that represents values between 10-15 using letters A-F.

Uploaded by

priyanka
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Binary Notes

Unit 6 discusses binary numbers and how computers use binary to represent data. It explains that binary uses only two digits, 1 and 0, to represent all numbers and characters. Individual bits make up nibbles (4 bits) and bytes (8 bits). Multiple bytes then form larger units like 16-bit and 32-bit words that can represent larger numeric values. The document provides examples of how binary numbers are converted to their decimal equivalents by assigning place values to each bit based on powers of two. It also introduces hexadecimal as a base-16 numbering system used by computers that represents values between 10-15 using letters A-F.

Uploaded by

priyanka
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 16

Unit SIX

Binary numbers can be from 1 digit to infinity. But for our uses, there aren't too
many numbers that we can't live without that can't be represented by 32-bit or 64-
bit binary numbers. Let's start with the basics.

To the computer, binary digits aren't really 1s and 0s. They're actually electrical
impulses in either a (mostly) on state or a (mostly) off state. Just like a switch -
either on or off. Since you only have 2 possible switch combinations or electrical
possibilities, the computer only needs various combinations of 2 digits to represent
numbers, letters, pixels, etc. These 2 digits, for our sake are visually represented by
1s and 0s.

A single binary 1 or a single binary 0 is called a bit, which is short for "binary digit".
A single bit by itself isn't of much use to the casual user, but can do wonders in the
hands of a programmer working at the system level.

Take 4 of these bits and slap them together and they now form what's called a
nibble (though this term isn't used very often). A nibble can represent the decimal
values 0 to 15 (16 distinct values).

1 0 1 0
4-bit (Nibble) Sample

Take 8 bits and put them together and you have one of the mostly commonly used
computer terms in existence - the byte. A single byte can represent the decimal
values 0 to 255 (256 distinct values) and since every possible character you can
type on an English keyboard is represented by a number less than 128 to the
computer (called ASCII codes) , a single letter of the alphabet takes 1 byte to
represent internally (technically, you can represent all the letters of the alphabet
using only 7-bits of a byte, but we won't get into that). When we speak of how much
ram a computer has, we say it has 256-megabytes of ram, meaning 256 million
bytes (most people nowadays just say 256 megs of ram and leave off the byte
word).

1 0 1 1 1 0 1 0
8-bit (1 Byte) Sample

Place a couple of bytes together to represent a single value and you have a 16-bit
word (2 bytes = 16-bits). A 16-bit word can represent the values 0 to 65535
(65536 distinct values). In the old days 16-bit words were used to form the
addresses of 8-bit computers such as the Commodore 64, the Atari 800, and the
Apple IIs, to name a few. These 16-bit words which were big enough to store an
address for a 64k computer consisted of 2 bytes, a high byte and a low byte.

1 BYTE 1 BYTE

1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0
16-bit (2 Byte) Sample

1
32-bit words are 4 bytes in length. They can represent a value from 0 to
4,294,967,295 (4,294,967,296 distinct values).

1 BYTE 1 BYTE 1 BYTE 1 BYTE

1 0 0 1 1 1 0 1 1 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 0 0 0 1 1 1
32-bit (4 Byte) Sample

Pretty big number, but bigger still is the 64-bit word, which is, for you math-deprived
people, 8 bytes in length (8 bytes times 8 bits per byte).

1 BYTE 1 BYTE 1 BYTE 1 BYTE 1 BYTE 1 BYTE 1 BYTE 1 BYTE


1 0 1 1 0 0 0 1 1 1 1 0 1 1 0 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0 1 1 0 0 0 11

64-bit (8 Byte) Sample

This whopping monstrosity can represent a number from 0 to 1.844 E+19 if I


understand my calculator correctly.

Okay, enough about bits, bytes and words. Let's figure out how to read a lowly 8-bit
binary number.

As stated previously, a byte consists of 8 bits, each bit having the possible value of
either a 1 or a 0. Now when deciphering binary numbers, don't think of the 1 or 0 as
an actual value itself, but a flag to determine whether it has any importance in the
calculation of the final result. Lost? Let's look at an example:
Example binary number: 10001010 Binary representation of decimal 138.

Any time you're going to interpret a binary number, set something up on a piece of
paper that looks like this-

128 64 32 16 8 4 2 1

1 0 0 0 1 0 1 0

Now, look at those numbers above the boxes with the red 1s and 0s. Those are
decimal numbers representing powers of 2. Starting from the left and going to the
right they are 2 to the 7th power (2^7), 2 to the 6th power (2^6), 2 to the 5th
power (2^5), 2 to the 4th power (2^4), 2 to the 3rd power (2^3), 2 to the 2nd
power (2^2), 2 to the 1st power (2^1) and 2 to the 0th power (2^0):

2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0


It just so happens that with powers of 2, each successive number is double the one
before it. In other words if 2^0 is equal to 1 then 2^1 = 2 and 2^2 = 4 and 2^3 = 8
and so on. Here are the values of the powers of 2 going from 2^7 down to 2^0:

128 64 32 16 8 4 2 1

2
These are the values that are above the boxes. Now the actual binary number itself
consists of 1s and 0s in the blue boxes which somehow magically represents the
decimal number 138. How do we get 138 from 10001010? In the binary number
when you see a 1, multiply that 1 times the value that is directly over it. Where you
see a 0 in the box, just ignore it. So looking at our graphic again,
128 64 32 16 8 4 2 1

1 0 0 0 1 0 1 0

we see that there is a 1 under the 128, a 1 under the 8, and a 1 under the 2. If we
add only those numbers which have a binary 1 in the box under them, we come up
with 128+8+2 which equals 138.

Here's another example:

128 64 32 16 8 4 2 1

1 1 1 0 0 1 1 0

Thus, binary 11100110 is equal to 128+64+32+4+2 which is decimal 230

And another one:

128 64 32 16 8 4 2 1

1 0 0 0 0 0 0 1

Thus, binary 10000001 is equal to 128+1 which is decimal 129.

Hope this makes more sense than when you started. Be sure to check out the
section on Binary Finger Counting to learn how to count to 31 on one hand. See ya!

Ah, hexadecimal. If you've ever worked with colors in web page design, you've
proably seen something like '<body bgcolor="#A09CF3"> or something to that
effect. Somehow, that 6 digit hexadecimal number is equal to a lavender or light
purple color. What on earth does 'A09CF3' mean? Before we explain that, let's look
at what hexadecimal (hex) is.

Our decimal system, as mentioned in my Binary Tutorial, is a base-10 system, meaning


we can count to any number in the universe using only 10 symbols or digits, 0 thru
9.

For the computer, a 10-based system probably isn't the most efficient system, so the
computer uses binary (in reality, it uses microscopic switches which are either on or
off, but we represent them using the digits '1' and '0'). Unfortunately, binary isn't
very efficient for humans, so to sort of find a happy middle ground, programmers
came up with hexadecimal.

Hexadecimal is a base-16 number format (hex=6, decimal=10). This means that


instead of having only the digits from '0' to '9' to work with like our familiar decimal,

3
or '1' and '0' like binary, we have the digits '0' to '15'. It also means that we are
using the powers of 16, instead of the powers of 2 like in binary.

Digits '0' thru '9' are the same as our decimal system, but how can 10 thru 15 be
digits? Well, since there are no 10 thru 15 symbols, we have to invent some.
To count beyond 9 in hexadecimal, we use A thru F of the alphabet:
DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
HEXADECIMAL 0 1 2 3 4 5 6 7 8 9 A B C D E F
As soon as you count over 9 in hex, new digits take over. A=10, B=11, C=12, D=13,
E=14 and F=15. Alright, so we have 6 new digits we never saw before. What can we
do with them?
Binary Finger Counting: 1 to 7
The thumb represents the value 1, the index is double that, so it's 2, and the middle
is double the index, so it's 4, etc. This is key to understanding and fluently counting
in binary on your fingers.

To make the number 3 for instance, you have to combine a 2 finger and a 1 finger
(2+1=3).

Binary Finger Counting: 8 to 13


The thumb represents the value 1, the index is double that, so it's 2, and the middle
is double the index, so it's 4, etc. This is key to understanding and fluently counting
in binary on your fingers.

To make the number 11 for instance, you have to combine an 8 finger, a 2 finger and
a 1 finger (8+2+1=11).

Binary Finger Counting: 14 to 19


The thumb represents the value 1, the index is double that, so it's 2, and the middle
is double the index, so it's 4, etc. This is key to understanding and fluently counting
in binary on your fingers.

To make the number 18 for instance, you have to combine a 16 and a 2 finger

4
(16+2=18).

Binary Finger Counting: 20 to 25


The thumb represents the value 1, the index is double that, so it's 2, and the middle
is double the index, so it's 4, etc. This is key to understanding and fluently counting
in binary on your fingers.

To make the number 23 for instance, you have to combine the 16 finger, the 4
finger, the 2 finger and the 1 finger (16+4+2+1=23).

Binary Finger Counting: 26 to 31


The thumb represents the value 1, the index is double that, so it's 2, and the middle
is double the index, so it's 4, etc. This is key to understanding and fluently counting
in binary on your fingers.

To make the number 28 for instance, you have to combine the 16 finger, the 8
finger, and the 4 finger (16+8+4=28).

Logic gate
A logic gate performs a logical operation on one or more logic inputs and produces a
single logic output. The logic normally performed is Boolean logic and is most
commonly found in digital circuits. Logic gates are primarily implemented electronically
using diodes or transistors, but can also be constructed using electromagnetic relays,
fluidics, optical or even mechanical elements.

Logic levels

5
A Boolean logical input or output always takes one of two logic levels. These logic levels
can go by many names including: on / off, high (H) / low (L), one (1) / zero (0), true (T) /
false (F), positive / negative, positive / ground, open circuit / close circuit, potential
difference / no difference, yes / no.

For consistency, the names 1s and 0s are used.

Logic gates
A logic gate takes one or more logic-level inputs and produces a single logic-level output.
Because the output is also a logic level, an output of one logic gate can connect to the
input of one or more other logic gates. Two outputs cannot be connected together,
however, as they may be attempting to produce different logic values. In electronic logic
gates, this would cause a short circuit.

In electronic logic, a logic level is represented by a certain voltage (which depends on the
type of electronic logic in use). Each logic gate requires power so that it can source and
sink currents to achieve the correct output voltage. In logic circuit diagrams the power is
not shown, but in a full electronic schematic, power connections are required.

NAND gate INPUT OUTPUT


A B A NAND B

The NAND gate is a digital logic gate that behaves according to 0 0 1


the truth table to the right. A LOW output results only if both the 0 1 1
inputs to the gate are HIGH. If one or both inputs are LOW, a 1 0 1
HIGH output results.
1 1 0
Symbols
There are two symbols for NAND gates: the 'military' symbol and the 'rectangular'
symbol.

'Military' NAND symbol

'Rectangular' NAND symbol

Hardware description and pinout

6
NAND gates are basic logic gates, and as such they are recognised in CMOS ICs.

CMOS version

The standard, 4000 series, CMOS IC is the 4011, which includes four independent, two-
input, NAND gates. The pinout diagram is as follows:

Pinout diagram of a 4011 quad NAND IC


1 Input A1
2 Input B1
3 Output Q1
4 Output Q2
5 Input B2
6 Input A2
7 Vss
8 Input A3
9 Input B3
10 Output Q3
11 Output Q4
12 Input B4
13 Input A4
14 Vdd

TTL version

The 4011's TTL counterpart is the 7400 from the 7400 series. Here is its pinout diagram,
with a photo of a typical 7400 IC:

7
Pinout diagram and photo of a 7400 quad NAND IC
1 Input A1
2 Input B1
3 Output Q1
4 Input A2
5 Input B2
6 Output Q2
7 Ground
8 Output Q3
9 Input B3
10 Input A3
11 Output Q4
12 Input B4
13 Input A4

Besides the standard 2-input NAND gate, 3-, 4- and 8-input NAND gates are also
available:

 CMOS
o 4023: Triple 3-input NAND gate
o 4012: Dual 4-input NAND gate
o 4068: Mono 8-input NAND gate
 TTL
o 7410: Triple 3-input NAND gate
o 7420: Dual 4-input NAND gate
o 7430: Mono 8-input NAND gate

The NAND gate is the easiest to manufacture, and also has the property that any other
logic gate can be made from a combination of NAND gates. Therefore, NAND gates
usually form the basis of all other logic hardware.

8
TTL NAND gate

AND gate
INPUT OUTPUT
A B A AND B
The AND gate is a digital logic gate that implements logical 0 0 0
conjunction - it behaves according to the truth table to the right. A
HIGH output (1) results only if both the inputs to the AND gate are 0 1 0
HIGH (1). If neither or only one input to the AND gate is HIGH, a 1 0 0
LOW output results.
1 1 1

Symbols
There are two symbols for AND gates: the 'military' symbol and the 'rectangular' symbol.
These are also known as the 'American' and 'British' symbols.

'Military' AND Symbol

'Rectangular' AND Symbol

Hardware Description and Pinout


AND Gates are basic logic gates, and as such they are recognised in TTL and CMOS ICs.
The standard, 4000 series, CMOS IC is the 4081, which includes four independent, two-
input, AND gates. The pinout diagram is as follows:

9
1 Input A1 2 Input B1 3 Output Q1 4 Output Q2 5
Input B2 6 Input A2 7 Vss 8 Input A3 9 Input B3 10
Output Q3 11 Output Q4 12 Input B4 13 Input A4 14
Vdd

Pinout Diagram of a 4081 Quad


AND DIL-format IC

This device is available from most semiconductor manufacturers such as Philips. It is


usually available in both through-hole DIL and SOIC format.

As well as the standard 2-Input AND Gate, 3-, 4- and 8-Input AND Gates are also
available:

 4073: Triple 3-Input AND Gate


 4082: Dual 4-Input AND Gate
 An 8-Input NAND Gate exists (4068), and this is easily made into an 8-Input
AND gate by inversion of the output.

An AND gate is usually designed using NMOS or


PNOS MOSFETs as shown in the schematics to the left.
The digital inputs a and b cause the output F to have the
same result as the AND function.

AND Gate Constructed Using Only NAND Gates

If no specific AND gates are available, one can be made


from NAND or NOR gates, because NAND and NOR
gates are considered the "universal gates"[1] which can
be used to make all the others. The configuration shown
on the right shows how to use NAND gates to create the
effect of an AND gate.

OR gate

10
INPUT OUTPUT
A B A OR B
The OR gate is a digital logic gate that implements logical 0 0 0
disjunction - it behaves according to the truth table to the right. A
0 1 1
HIGH output (1) results if one or both the inputs to the gate are
HIGH (1). If neither input is HIGH, a LOW output (0) results. 1 0 1
1 1 1
Symbols
There are two symbols for OR gates: the 'military' symbol and the 'rectangular' symbol.

'Military' OR Symbol

'Rectangular' OR Symbol

Hardware Description and Pinout


OR Gates are basic logic gates, and as such they are recognised in TTL and CMOS ICs.
The standard, 4000 series, CMOS IC is the 4071, which includes four independent, two-
input, OR gates. The pinout diagram is as follows:

1 Input A1
2 Input B1
3 Output Q1
4 Output Q2
5 Input B2
6 Input A2
7 VSS
8 Input A3
9 Input B3
10 Output Q3
11 Output Q4
12 Input B4
13 Input A4
Pinout Diagram of a 4071 Quad OR DIL-format IC 14 VDD

This device is available from most semiconductor manufacturers such as Philips.

As well as the standard 2-Input OR Gate, 3- and 4-Input OR Gates are also available:

 4075: Triple 3-Input OR Gate


 4072: Dual 4-Input OR Gate

11
Implementations

] Alternatives

OR Gate Constructed Using Only NAND Gates

If no specific OR gates are available, one can be made from NAND gates in the
configuration shown below. Interestingly, any logic gate can be made from a combination
of NAND gates

With active-low open-collector logic outputs, as used for control signals in many circuits,
an OR function can be produced by wiring together several outputs. This arrangement is
called a wired OR.

NOT gate

INPUT OUTPUT
The NOT gate or inverter is a digital logic gate that implements A NOT A
logical negation. It behaves according to the truth table to the right.
0 1
A HIGH output (1) results if the inputs is LOW (0). If the input is
HIGH (1), a LOW output (0) results. 1 0

Symbols
There are two symbols for NOT gates: the 'military' symbol and the 'rectangular' symbol.

12
'Military' NOT Symbol

'Rectangular' NOT Symbol

Hardware Description and Pinout


NOT Gates are basic logic gates, and as such they are recognised in TTL and CMOS ICs.
The standard, 4000 series, CMOS IC is the 4049, which includes six independent NOT
gates. The pinout diagram is as follows:

1 Vdd
2 Output Q1
3 Input A1
4 Output Q2
5 Input A2
6 Output Q3
7 Input A3
8 Vss
9 Input A4
10 Output Q4
11 Input A5
12 Output Q5
13 n.c.
Pinout Diagram of a 4049 Hex Inverting Buffer (NOT Gate) DIL-format 14 Input A6
IC 15 Output Q6
16 n.c.

This device is available from most semiconductor manufacturers such as Philips.

Implementations

NMOS NOT gate PMOS NOT gate Transistor-Transistor logic NOT gate

Alternatives

13
NOT gate constructed using only a NAND gate

If no specific NOT gates are available, one can be made from NAND gates in the
configuration shown below. Alternatively, a NOR gate could be used in the same
configuration. Any logic gate can be made from a combination of NAND gates or NOR
gates.

NOR gate
INPUT OUTPUT
The NOR gate is a digital logic gate that implements logical NOR - A B A NOR B
it behaves according to the truth table to the right. A HIGH output 0 0 1
(1) results if both the inputs to the gate are LOW (0). If one or both
input is HIGH (1), a LOW output (0) results. NOR is the result of the 0 1 0
negation of the OR operator, thus forming a complete operation the 1 0 0
combination of which can be combined to generate any other logical 1 1 0
function. By contrast, the OR operator is monotonic as it can only
change LOW to HIGH but not vice versa.

In most, but not all, circuit implementations, the negation comes for free (e.g. CMOS) --
in some logic families it is required and OR has to be implemented as a NOR followed by
an inverter.

Symbols
There are two symbols for NOR gates: the American ('military') symbol and the IEC
('European' or 'rectangular') symbol. For more information see Logic Gate Symbols.

American NOR Symbol

IEC NOR Symbol

Hardware Description and Pinout


NOR Gates are basic logic gates, and as such they are recognised in TTL and CMOS ICs.
The standard, 4000 series, CMOS IC is the 4001, which includes four independent, two-
input, NOR gates. The pinout diagram is as follows:

14
1 Input A1
2 Input B1
3 Output Q1
4 Output Q2
5 Input B2
6 Input A2
7 VSS
8 Input A3
9 Input B3
10 Output Q3
11 Output Q4
12 Input B4
13 Input A4
Pinout Diagram of a 4001 Quad NOR format IC 14 VDD

This device is available from most semiconductor manufacturers such as Philips. It is


usually available in both through-hole DIL and SOIC format. Datasheets are readily
available in most Datasheet Databases. Two NOR gates can be used to make a latch.

As well as the standard 2-Input NOR Gate, 3- and 4-Input NOR Gates are also available:

 4000: Dual 3-Input NOR Gate and Inverter


 4002: Dual 4-Input NOR Gate

Implementations

NOR Gate Constructed Using Only NAND Gates

If no specific NOR gates are available, one can be made from NAND gates in the
configuration shown below. Interestingly, any logic gate can be made either from a
combination of NAND gates or from a combination of NOR gates.

15
A Boolean algebra is a set A, supplied with two binary operations (called AND),
(called OR), a unary operation (called NOT) and two distinct elements 0 (called zero)
and 1 (called one), such that, for all elements a, b and c of set A, the following rules
apply:

associativity
commutativity
absorption

distributivity
complements

16

You might also like