Chapter 4

The Building Blocks: Binary Numbers, Boolean Logic, and Gates

By the end of this chapter, you will learn how binary is used to represent different numbers and information on a computer. You will be able to convert between bases (binary, decimal, octal, etc.) and also use two's complement to represent signed numbers. Furthermore, you will learn about Boolean algebra and logic gates.

The Binary Numbering System

Computers represent information through binary

Binary Representation of Numeric and Textual Information

External representation of numbers or text often takes the form of letters or decimal numbers. However, internal representations in computers are in binary.

Binary is a base 2 system as opposed to the common decimal system which is in base 10. There are only 1 and 0.

One digit in binary is called a "bit"

To convert from binary to decimal, start from the right of the binary number and multiply the binary number by the power of base 2. For example, for the binary number 10111, you would start at the 1 at the very right and multiply it by 2 to the power of 0. Then you would move left and multiply the next number by 2 to the power of 1. After you do this for all bits, add the values together to get the decimal number.


Refer to the image below to convert between decimal and binary



If a value goes beyond what a binary number can store, it is called an arithmetic overflow

When adding binary digits, 0+1 would be 1 and 1+1 would be 10. The 1 in the 10 is carried and added to the next bit.

Signed Numbers

Sign mangnitude notation is used to represent positive and negative numbers. A 0 at the left of the binary value represents a positive number and a 1 at the left of the binary value represents a negative number.

The problem is that the computer cannot tell the difference between a signed binary value or an unsigned binary value.

To solve the problem, two's complement is used to represent signed digits. To put a binary value in two's complement form, flip the bits (1 becomes a 0 and vice versa) and add 1 to the flipped binary value.

Fractional Numbers

Scientific notation is used to represent signed decimal numbers


M=Mantissa, B=Base, E=Exponent


Textual Information

ASCII uses an 8 bit representation which allows for 256 unique characters. Unicode uses a 16 bit representationw hich allows for 65536 unique characters.

Binary Representation of Sound and Images

Digital representations are things such as textual or numeric information (finite). Analog representations are able to represent any values.

Amplitude is the height of a soundwave (sound is louder when the amplitude is higher). Period is the time for a wave to cycle once. Frequency is the amount of cycles in a period of time (usually in hertz).

Analog representations are usually turned into a digital representation where sampling occurs. Sampling is taking segments of the wave and measuring the amplitude.

Bit depth is the number of bits per sample.

Raster graphics assign a unsigned binary value to a pixel. An example is JPEG. Most images are represented using the RGB encoding scheme (red, green, blue). Each color is provided 1 byte. True color is 24 bits.

Compression ratio is size of uncompressed data divided by size of compressed data.

The Reliability of Binary Representation

Binary is reliable compared to other number systems. Decimal systems are in base 10 which requires 10 stable energy states which is very unreliable.

Binary Storage Devices

A transistor is used to as an on/off switch.

Boolean Logic and Gates

Boolean Logic

Centered around true/false.

Basic operations are AND, OR, and NOT

Truth Table Example:


Gates

Gates take in a binary input and return a binary output.

Control Circuits

Multiplexer: Contains 2^N input lines and 1 output line. N is the number of selector lines.

Decoder: N input lines and 2^N output lines.