Binary
Objectives
We would like to :- Understand why we use binary in modern computers.
- Understand the basics of binary.
Notes
- This is mostly from Carpinelli
- Base 2 is called binary.
- Base 8 is called octal
- Base 16 is called hexadecimal, or hex.
- Computers natively use base 2.
- In the past there have been attempts to use other base
- In the future they may be computers that use other bases.
- But for now, you would be very hard pressed to find a computer that does not use base 2.
- Why?
- The electronics of base two are simpler
- Digital vs analog
- In a digital system data is represented as digits.
- Discrete, the data is broken into bins.
- This is easier to read
- In an analog system data is represented as positions.
- Continuous, perhaps more accurate
- The data is continuous wrt time.
- The real world is probably continuous.
- In a digital system data is represented as digits.
- So some form of continuous (we hope) electric power is driving our computers.
- It may go from a low of 0 volts to a high of +5 volts.
- But there will be noise
- It is easy to draw one line (or perhaps two) and say that everything below the line is one value and everything above the line is another.
- With two lines, the middle will be unknown/error/ .
-
- Capanelli has a table that discusses various forms of logic.
- ttl, the one we will be using is a 5v system.
- 0V to .4V is logical 0
- 2.7V to 5V is logical 1
- Also, we will see an entire set of algebra that deals well with base 2.
- In general we
- Use 0/1 for our symbols in binary.
- In logic we use F/T or false/true
- For this class we will use 0/1
- And I don't care what your discrete/formal logic instructor says.
- But do what they ask in their class.
- Use 0/1 for our symbols in binary.
- In computing
- A signal binary digit is called a bit.
- 8 bits form together to make a byte.
- A word is machine dependent, but usually between 2 and 8 bytes.
- For intel assembly, we consider a word 2 bytes.
- A double word is 4 bytes
- A quad word is 8 bytes
- A 32 bit machine is 32/8 or 4 bytes
- A 64 bit machine is 64/8 or 8 bytes.
- Memory is byte addressable.
- For larger quantities we use
- The SI standard
- 1000 or 103 is a kilobyte (k)
- 106 is a megabyte (M)
- 109 is a gigabyte (G)
- 1012 is a terabyte (T)
- 1015 is a petabyte (P)
- 1018 is an exabyte
- zetta, yotta, ronna and quetta are next.
- See nist.
- But we also h ave a binary prefix system
- 1024 or 210 is a kibibyte (k)
- 220 is a mebiyte (M)
- 230 is a gibiyte (G)
- 240 is a tebiyte (T)
- 250 is a pebiyte (P)
- 260 is an exbite
- zetta, yotta, ronna and quetta are next.
- See wikipedia.
- Rant for a moment.
- The SI standard
- Some binary numbers
- Count 0 to 16 in binary.
- Convert 101101012 to decimal.
- You need to be comfortable working with binary numbers.
- Converting from decimal to binary (integer)
- We want to find the powers of two "in a number"
- We can do this by repeated division.
- Let's try this on something easy like 12
12/2 = 6 r 0 6/2 = 3 r 0 3/2 = 1 r 1 1/2 = 0 r 1
- Using this trick, we read the remainders backwards to get the binary representation 11002
-
DECIMAL-TO-BINARY Input: an integer in decimal d Output: an integer in binary b (you might think of this as a string)- b = 0
- While d > 0
- r = d % 2
- d = d / 2
- b = cat(r,b) (concatenation)
- return b