1
1. Introduction 2. BinaryRepresentation 3. HardwareandSoftw are 4. HighLevel Languages 5. Standard inputand output 6. Operators, expression and statem ents 7. M akingDecisions 8. Looping 9. Arrays 10. Basicsof pointers 11. Strings 12. Basicsof functions 13. M
- reabout functions
14. Files 14. DataStructures 16. Casestudy:lotterynum bergenerator
Lecture 2
Binary Number Systems
- Decimal is a base 10 number system
– 1’s, 10’s, 100’s, 1000’s etc
- Binary is just a base 2 number system
– 1, 2, 4, 8, 16 etc
- A binary variable can have 2 states
– 1/0, on/off, +5v/0v
- For example, the binary equivalent of the
decimal number 26 is 11010,
which is 11010 = 1x24 + 1x23 + 0x22 + 1x21 + 0x20
Binary Number Systems
- bit
– One binary digit 0 or 1.
- byte
– A group of 8 bits capable of representing binary numbers from 0-255 i.e. 10010101
- nibble
– A group of 4 bits, i.e. 1001
- word
– Most computer systems organise their memories in groups of bytes called words. An eight-bit word consists of one byte, a sixteen-bit word consists of two bytes, a thirty-two-bit word consists of four bytes, and so on.
Other Number Systems
- Hexadecimal and Octal Number Systems
– Binary numbers are a convenient representation for manipulation by digital computers, but not by human beings. It is often advantageous to convert a binary number into its hexadecimal (base 16) or octal (base 8) representation. The following table shows the representation of numbers in decimal, binary, octal and hexadecimal.
Decimal Binary Octal Hexadecimal 00 0000 00 01 0001 01 1 02 0010 02 2 03 0011 03 3 04 0100 04 4 05 0101 05 5 06 0110 06 6 07 0111 07 7 08 1000 10 8 09 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F
Number System Conversion
e.g. the decimal value 77 is represented as a binary byte thus 7710 = 0100 1101 and in hexadecimal and octal as 4D and 115 respectively 0100 1101 01 001 101 4 D 1 1 5 By knowing the binary code for hexadecimal and octal digits, the binary code for multi-byte numbers can be easily constructed. The binary representation of the four byte value #1EA7 (where # denotes hexadecimal) is 0001 1110 1010 0111 1 E A 7
Logical Operations on Binary Number Systems
A B f 1 1 1 1 1 A B f 1 1 1 1 1 1 1 A f 1 1 A B f 1 1 1 1 1 1