What is binary? - Stephanie Hartley

advertisement
BINARY AND NUMBER BASES
Steph Hartley
ORGANIZATION [Company address]
What is binary?
Binary is a number system, used by all computers, that can have only
one of two values. Computers operate in binary, meaning they
store data and perform calculations using only zeroes and ones.
A single binary digit can be used to represent True (1) or False (0),
multiple binary digits can be used to store large numbers and
perform complex functions. In fact, any number can be represented
in binary. Binary is used to store data within computers, on hard
drives and in many other places, everything is a 1 or 0.
Bit – short for binary digit, a bit is the smallest unit of data. A bit is
represented as a 1 or 0.
Nibble – half a byte or for bits, nibble is not commonly used for
anything.
Byte – Made up of 8 bits. A single letter/character typed is stored as
1 byte.
Kilobyte – unit of computer storage. 1 kilobyte is the equivalent of
1024 bytes. (not very big.) some files will be small enough to only
take up kilobytes of space.
Megabyte – unit of computer storage. 1 megabyte is the equivalent
of 1024 kilobytes. Large files take up megabytes of spce.
Gigabyte - unit of computer storage. 1 gigabyte is equivalent to 1024
megabyte of storage. UBS sticks are usually measured in gigabytes,
for example a 64 GB memory stick is 64 gigabytes, external and
internal hard drive are also measured in GB.
Terabyte - unit of computer storage. 1 terabyte is equivalent to 1024
gigabytes of storage. The latest hard drives are usually measured in
terabytes, for example a 1 TB hard drive is 1 terabyte.
What is a Number Base/number systems?
The most common number system is base 10 or denary. Base 10 is
the number system that people use every day, 0 to 9.
Number bases are different ways of writing and using the same
number.
All number bases use column headings or place values the same way
base ten does.
Base 10 uses units, tens, hundreds, thousands, etc. The value of
each place value is calculated by multiplying by 10 or the power of ten.
Other number bases do this but they just have different values for
the place value.
Different types of number base
There are lots of different number bases but the most common are
binary – base 2, denary – base 10 and hexadecimal – base 16. Al
number bases work in the same way and you can represent any
number in any number base.
Base 2 – binary works to the power of two so the place values for
binary are
128 64 32 16 8 4 2 1
Base 10 – Most common number system used by people day to day
to do maths. The pace values for base 10 are
1000 100 10
1
of course they can go high.
Base 16 - Hexadecimal stores data like binary does but hex is most
commonly used for colours when coding, for example #ff39ff
Base 16 works to the power of 16 so the place values are
268,435,456 16,777,216 1,048,576 65,536 4,096 256 16 1
ASCII
A- American
S- Standard
C- Code
I- Information
I- Interchange
ASCII is a code for representing English characters as numbers, with
each letter assigned a number from 0 to 127. For example, the ASCII
code for uppercase M is 77. Most computers use ASCII codes to
represent text, which makes it possible to transfer data from one
computer to another.
Converting base 10 binary and binary to base 10
Base 10 to binary
Take 165
Write out the place values for binary
128
64
32
16
8
4
2
1
The start from the left and if there’s 128 in the number you are
converting put a 1
128
64
32
16
8
4
2
1
1
so now there’s 37 left over, if there’s not 64 left then put 0
128
64
32
16
8
4
2
1
1
0
now continue from left to right
128
64
32
16
8
4
2
1
1
0
1
0
0
1
0
1
so 165 in denary = 10100101 in binary.
Binary to base 10
Take 00100110 in binary
Write out with the place values
128
64
32
16
8
4
2
1
0
0
1
0 0 1 1 0
add up every place value that has a one
so for this one we have
32
4
2
and add them together
32+4+2 = 38
so 00100110 in binary is 38 in base 10
Converting binary to hexadecimal
Hexadecimal in made up of characters 0-9 and A-F
0123456789ABCDEF
A – F represent 10 - 15
Take a binary number
11001111
split it in to two nibbles and add the place value above
8 4 2 1
8 4 2 1
1 1 0 0
1 1 1 1
now add up the values
8 4 2 1
8 4 2 1
1 1 0 0
1 1 1 1
= 12
= 15
12 in hex = C
15 in hex = F
so 11001111 in binary = CF in hexadecimal
Adding binary
Adding two numbers in binary is different to adding two numbers in
denary/base ten.
There are four rules to remember when adding binary
0+0=0
1+0=1
1 + 1 = 10 (2 in binary)
1 + 1 + 1 = 11 (3 in binary)
so now lets add two binary numbers 01001100 + 00111100
lay it out with one number above the other
01001100
+00111100
start from the right hand side and add the number together one
column at a time
01001100
+00111100
0+0 = 0
put the result under the line in the relevant column
01001100
+00111100
0
Continue from left to right
0+0 = 0
01001100
+00111100
00
next sum is
1+1 = 10
in this case add the 0 to the next column and carry the one.
01001100
+00111100
000
1
the next sum is 1 + 1 + 1 because of the carry over from the previous
sum
1+1+1=11
add 1 in the relevant column and carry a 1
01001100
+00111100
1000
11
Continue this process until the end of the binary numbers
01001100
+00111100
10001000
11111
to check this right convert all three numbers back to denary do the
sum in denary
128 64 32 16 8 4
2
1
0
1
0
0
1
1
0
0 = 76
0
0
1
1
1
1
0
0 = 60
1
0
0
0
1
0
0
0 = 136
76 + 60 = 136
Overflow errors can happen where the last column has a carrier
which will cause an extra digit at the start of the number this will
either cause the program to crash or the program will ignore the
start number and give a unexpected result.
Subtracting binary
28 – 4 = 28 + (-4)
To subtract 2 binary numbers, you need 1’s compliment and 2’s
compliment. For this example you have to change the 4 using 1 and
2’s compliment.
1’s compliment means all the 0 in a byte are changed to 1’s and all
the 1’s change to 0’s
for example
0 0 0 0 0 1 0 0 – binary digit
1 1 1 1 1 0 1 1 – 1’s compliment
to get 2’s compliment you need to add 1 to 1’s compliment
1 1 1 1 1 0 1 1 – 1’s compliment
+0 0 0 0 0 0 0 1 – plus 1
1 1 1 1 1 1 0 0 – 2’s compliment
11
28 in binary
128
0
1
1 0
1
64
32
16
8
4
2
1
0
1
0
1
0
1
0
1
1
1
1
1
1 1
1 1
1 0
1
0
0
0
0 = 28
0 = +(-4)
0 = 24
the answer is 24 because the extra 1 at the start is ignored.
Multiplying binary
Binary multiplication uses three simple rules
0x0=0
1x0=0
1x1=1
these are the same in binary and decimal
Take this binary multiplication
101
x 11
you use the same system and base 10 multiplication
so take the bottom number and multiple the top number by the 1 on
the right
101
x 11
101
now do the same for the 1 on the left but don’t forget the 0 on the
right
101
x 11
101
1010
now all you need to do it is add these two numbers
101
+1010
1111
to check this, convert the numbers to denary
101 = 5
11 = 3
5 x 3 = 15
1111 = 15
Download