Computing - Data representation (binary and hexadecimal)
What do alphanumeric characters include?
- Uppercase/lowercase letters - Digits 0 - 9 - Symbols
What can you do when converting denary to binary if the number is 1 less than one of the headings (e.g; 127)?
You can put 0 in the column that it is 1 less than, and put 1s in the rest of the columns, e.g; 127 = 0111 1111
How to convert binary to hexadecimal:
1. Split the binary into nibbles (4 bits) 2. Put each nibble in its own table with headers 8 to 1 (dividing by 2 each time) 3. Add together each column that has a 1 in it 4. Convert that value into hex 5. Do that to each column and then put it together
How to convert hexadecimal to binary:
1. Split the hexadecimal number into single digits 2. Convert each single digit into denary 3. Convert the denary into binary using the table with the headings 8 to 1 (dividing by 2 each time) and the subtraction technique 4. Put each nibble together to form the whole binary number
How to convert denary to binary:
1. Write out table with a heading 128 to 1 (dividing by two each time) 2. Starting at the left put a 1 if your number is bigger and subtract that number from yours 3. Do the same with the remainder, putting a 0 and moving on to the next if it is smaller 4. Note: once the remainder is 0, stop and fill the rest of the columns with 0s
How to convert binary to denary:
1. Write out table with a heading 128 to 1 (dividing by two each time) 2. Write your binary number under each of the headings 3. Add up all the numbers with 1 in their column
What is our standard number system?
10 digits; called denary, decimal or base-10
What is hexadecimal?
16 digits; base-16
What is binary?
2 digits; base-2
How to add binary:
- Use column addition - If there are two 1s carry it - If you carry a 1 and there are two 1s in the column (aka 1 + 1 + 1), put 1 and then carry the 1 again
What are the 16 hex characters?
- 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - a - b - c - d - e - f
What are the most common Unicode forms?
- 16-bit binary - 32-bit binary
What is extended ASCII?
- A character set which gives each character an 8-bit binary code - This allows for 256 characters to be represented - The first 128 characters are in exactly the same order as the ASCII characters
Examples of standard character sets:
- ASCII - Extended ASCII - Unicode
What do character sets include?
- All alphanumeric characters - Special characters that do certain commands (e.g; space, enter, delete)
Different number systems:
- Denary - Binary - Hexadecimal
What is a right shift?
- Divides a binary number - For every place shifted right, the number is halved
How does ASCII work?
- Each ASCII character is given a 7-bit binary code (covers all letters in English alphabet, numbers symbols and commands) - An extra bit (0) is added to the start of the binary code for each ASCII character so that each ASCII character fits nicely into 1 byte
Why do programmers prefer hex when coding?
- It's simpler to remember large numbers in hex as they are much shorter - Less chance of input error as they are much shorter - Easier to convert between binary and hex than binary and denary
How do computers deal with overflow?
- Most computers store extra bits elsewhere - Some computers see it as an overflow error and ignore it (which can lead to a loss of data and loss of accuracy in your answer) - It can cause software to crash if it doesn't have a way of dealing with the extra bit
What is a left shift?
- Multiplies a binary number - For every place shifted left, the number is doubled
What is ASCII?
- Stands for American Standard Code for Information Interchange - The most commonly-used character set in the English-speaking world
What is Unicode?
- Unicode is used for internal representation of characters and strings - It comes in several different forms and tries to cover every possible character that might be written
What are alphanumeric characters?
A mix of letters ("alpha") and numbers ("numeric")
What does a single hex character equate to in binary?
A nibble (4 bits)
How does single hex character equate to a nibble in binary?
A single hex character can represent any denary number from 0 - 15, to represent 0 - 15 in binary would require 4 bits. Therefore one hex character = a nibble (4 bits)
What are binary shifts?
Also called logical shifts; they are a process that moves every bit in a binary number left or right a certain number of places
What are the gaps created by binary shifts filled in with?
Any gaps are filled in with '0'
What can right shifts cause?
Bits can 'drop off' the end which can lead to loss of accuracy/data
How do computers understand alphanumeric characters?
By using character sets
What are character sets?
Collections of characters that a computer recognises from their binary representation
What is the problem with alphanumeric characters?
Computers are unable to process the characters directly as they only process binary code, so they need a way of converting these characters to binary code and vice versa
How to convert denary to hexadecimal:
Convert denary to binary: 1. Write out table with a heading 128 to 1 (dividing by two each time) 2. Starting at the left put a 1 if your number is bigger and subtract that number from yours 3. Do the same with the remainder, putting a 0 and moving on to the next if it is smaller 4. Note: once the remainder is 0, stop and fill the rest of the columns with 0s Convert binary to hexadecimal: 1. Split the binary into nibbles (4 bits) 2. Put each nibble in its own table with headers 8 to 1 (dividing by 2 each time) 3. Add together each column that has a 1 in it 4. Convert that value into hex 5. Do that to each column and then put it together
How to convert hexadecimal to denary:
Convert hexadecimal to binary: 1. Split the hexadecimal number into single digits 2. Convert each single digit into denary 3. Convert the denary into binary using the table with the headings 8 to 1 (dividing by 2 each time) and the subtraction technique 4. Put each nibble together to form the whole binary number Convert binary to denary: 1. Write out table with a heading 128 to 1 (dividing by two each time) 2. Write your binary number under each of the headings 3. Add up all the numbers with 1 in their column
What can different character sets have?
Different amounts of characters
What is overflow?
During binary arithmetic, you can get a result that requires more bits than the CPU is expecting
What do the number of characters in a character set determine?
How many bits you'll need
Why does ASCII use 7-bits?
It can represent a total of 128 different characters, including all the letters in the English alphabet, numbers, symbols and commands
What is useful about Unicode?
It covers all major languages, even those that use a completely different alphabet like Greek, Russian and Chinese
What are alphanumeric characters used for?
Making words and strings
What is extended ASCII useful for?
Many European languages like French and German which include accents on some vowels
What is the formula used for binary shifts?
Number divided/multiplied by = 2ⁿ where n is number of shifts
What can left shifts cause?
Overflow which can lead to loss of accuracy/data
What are overflow flags?
Something used to show that an overflow error has occurred