A-Level Computing#BristolMet Session Objectives#9 express numbers in binary, binary-coded decimal (BCD), octal and hexadecimal; describe and use two’s complement and sign and magnitude to represent negative integers; perform integer binary arithmetic, that is addition and subtraction Create a GCSE calculator using an IF ELSE statement
A-Level Computing#BristolMet Binary Arithmetic & BCD Starter: How many binary digits would be required for this hexadecimal code and what is the 8 bit binary equivalent: #FF9B22
GCSE Computing#BristolMet Converting Binary to Hexadecimal Denary 45 in binary is or Split into 2 nibbles and treated as 4 bits each: = 2 = 13 = 2D TASK: Using the same method convert a) b) Now try the reverse, convert to binary a) A5 b) 3B a) EB b) A3 a) b)
A-Level Computing#BristolMet Binary Coded Decimal (BCD) Binary Coded Decimal (BCD) uses 4 bit binary to represent decimal digits 0 – 9. You simply split the digits and treat the separately. For example, decimal 75 in BCD is as follows: 7 = 5 = Therefore 75 in BCD becomes: Now convert the following denary into BCD: a)39 b)58 c)97
A-Level Computing#BristolMet Binary Arithmetic Another reason why computers are designed to use binary is that addition is so simple in binary. In binary there are only 4 sums which need to be known: = = = = 0, carry 1 For example;Now try: 75 = a) = = 89b) Carry
A-Level Computing#BristolMet Sign & Magnitude So far we have learned how to store positive whole numbers in binary but there is a need to use negative numbers and fractions. You will remember that only 7 bits is need to represent the ASCII character set (127 characters) and this is the purpose of the 8th bit, to represent a +/- For example: +/ = = This is called sign/magnitude representation – the byte is in 2 parts, the sign (+/-) and the size of the number.
A-Level Computing#BristolMet 2s Complement There are 2 problems with sign & magnitude representation. Firstly, the biggest number that can be represented is now halved – 127 instead of 255. Secondly, arithmetic now made more complicated as different bits means different things. A solution to this is using a system called 2s complement – the last bit stands for So the diagram looks like this: So -75 in 2s complement is: =
A-Level Computing#BristolMet Subtraction in binary Now using 2s complement subtraction is easier because 75 – 14 is the same as 75 + (-14) = = = 61 Carry 1 1 Now attempt a) b) 43 – 58 Some more examples:Click HereClick Here Why binary arithmetic – Watch this videoWatch this video