Sunteți pe pagina 1din 4

University of Glasgow Department of Electronics and Electrical Engineering Binary numbers, reminder sheet

Binary numbers Binary numbers are numbers to the base 2. They therefore only need the symbols 0 and 1. They can thus easily be mapped on to the logical levels of digital electronics. Here is a table of the first few binary numbers and their decimal counterparts: Binary 0 1 10 11 100 101 Decimal 0 1 2 3 4 5

It can be seen immediately that the binary numbers require many more digits than their decimal equivalent.

Bits and bytes A single binary digit is called a bit. It is the smallest piece of information we can have. If numbers require many digits, they have a corresponding number of bits. Here are some examples: 0 1 101 1000 10110010 is is is is is 1 bit 1 bit 3 bits 4 bits, called a nybble 8 bits, called a byte

When mapped on to digital logic, numbers of many bits require many logical lines running in parallel to transmit them. Such a system of many logical lines in parallel is called a bus. When a number is being transmitted along such a bus we have to include the leading zeroes, here are some examples where the number is using 8 lines, i.e. an 8 bit bus, the lines are named A0, A1, A2, A3, A4, A5, A6, A7. Logical values A4 A3 0 0 0 0 0 0 0 1 0 0 binary value A2 0 0 0 0 0 A1 0 0 1 0 0 A0 0 1 0 0 0 0 1 10 1000 1000 0000 decimal value 0 1 2 8 128

A7 0 0 0 0 1

A6 0 0 0 0 0

A5 0 0 0 0 0

Converting from binary to decimal. We can use the binary place value to convert a binary number to decimal. Take the binary number 101111. Draw up a table showing the powers of 2 for each binary column. Power of two decimal equivalent binary digits 25 32 1 24 16 0 23 8 1 22 4 1 21 2 1 20 1 1

D.J.Muir 12/10/00

Add up those powers where the binary number is 1 to get 32 + 0 + 8 + 4 + 2 + 1 = 47. The decimal number equivalent to the binary value 101111 is 47. A quicker way is to use nested multiplication. See the example below. The rule is From left to right, multiply by 2 and add the next digit, till the end is reached. You will end up with a series of nested brackets, which is simple to evaluate. Using the example from above, 101111, (((((1x2+0)x2+1)x2+1)x2+1)x2+1) = 47 Converting from decimal to binary: To converting from decimal to binary use the technique of repeated division. Take as example the number 47. Divide by 2 and write down the remainder to get: 2 47 Now divide the answer by two and note down the remainder. 23 R 1 2 47 2 23 R 1 11 R 1

Continue till only a remainder is left.

2 47 2 23 2 11 2 5 2 2 2 1 0

R1 R1 R1 R1 R0 R1

read upwards

The answer is read off upwards from the list of remainders as: 101111.

Binary addition Addition in binary is the same as for decimal except only digits 1 and 0 are needed. Here is the simple addition of one bit. Note the carry 1 when 1+1 = 10. 0 0 0 0 1 1 1 0 1 1 1 0

Here is an example with multi-digit numbers, remember the carries. 1 + 1 0 0 11 0 1 01 0 1 11 1 1 1 0

Hexadecimal numbers Binary numbers are generally too long for easy human use. More often we translate them into hexadecimal numbers, that is numbers to the base 16. Since we only have digit symbols for 0..9 we need to invent symbols for 10, 11, 12, 13, 14, and 15. We use the letters a, b, c, d, e, f. The table below shows the correspondence. Hex numbers therefore look odd with the letters as well as numbers e.g. 1bf is a hex number. Often hex numbers have h or $ to distinguish them e.g. 1bf h, or $1bf.

D.J.Muir 12/10/00

Binary 0 1 10 100 1000 1001 1010 1011 1100 1101 1110 1111

Hexadecimal 0 1 2 4 8 9 a b c d e f

decimal 0 1 2 4 8 9 10 11 12 13 14 15

Converting hex to decimal This is done in the standard way by adding powers of 16. As an example use 1bf. The table below shows each power of 16, its decimal equivalent and the resulting decimal value of each hex column. Power of 16 Decimal equivalent Hex digit Decimal equivalent Decimal value of hex column 162 256 1 1 1x256 = 256 16 16 b 11 11x16 = 176 1 1 f 15 1x15 = 15

Thus the decimal value for 1bf is 256+176+15 = 437. Alternatively, use nested multiplication to get: (1x16+11)x16+15 = 437

Converting from decimal to hex. Use repeated division in the same way as for binary. Take the example of 156 decimal, divide by 16 repeatedly and keep a list of the remainders. 16 156 16 9 R 12 = c Read off the remainders from bottom to top to get 9c. 0 R9 Converting from binary to hex. Partition the binary number into groups of four digits. Then translate each group of four into the appropriate hex code. Take the example of binary number 11100111 1110 e Converting from hex to binary. Take as example hex 2ab. Translate each hex digit into the corresponding binary four, digit group. The binary number is then 10 1010 1011. 2 0010 a 1010 b 1011 0111 7

The hex number is e7.

D.J.Muir 12/10/00

Well Known Numbers


Decimal Binary 2x
2 3

hexadecimal
0 4 8 a f 10 20 40 80 ff 100 200 400 fff 1000 ffff 1 0000 10 0000

0 0 4 100 8 1000 10 1010 15 1111 16 1 0000 32 10 0000 64 100 0000 128 1000 0000 255 1111 1111 256 1 0000 0000 512 10 0000 0000 1,024 too big! 4,095 4,096 65,535 65,536 = 64 x 1024 1,048,576 =1024 x 1024

4 5 6 7 8 9 10 12 16 20

(called 1k)

(1 Meg )

These well known numbers are found when dealing with computer systems where the most often used unit is the byte. Hence powers of 2 from 0 to 8 are well worth remembering. Notice that a 4 bit number can store 16 values, 0 - 15. An 8 bit number, a byte, can store 256 values, 0 - 255.

D.J.Muir 12/10/00

S-ar putea să vă placă și