1.4.1 Data Types

Cards (66)

  • Convert the denary number 189 to hexadecimal (1 mark)
    • 189 / 16 = 11 remainder 13
    • BD
  • Convert the unsigned binary number 1010101111 to hexadecimal (1 mark)
    • 0010 = 2, 1010 = A, 1111 = F
    • 2AF
  • Data is always stored in binary by computers
  • It's essential to make sure data is being stored with the right data type when writing a program
  • Integer
    • An integer is a whole number that includes zero and negative numbers but can't have a fractional part. Integers are useful for counting things
  • Integer
    • 6
    • 47238
    • -12
    • 0
    • 15
  • Real
    • Real numbers are positive or negative numbers that can have a fractional part. They are useful for measuring things
  • Real
    • 0
    • -71.5
    • 5.01
    • -80.8
    • 15
  • Character
    • A character is a single symbol used by a computer, including letters A to Z, numbers 0 to 9, and various symbols like %, £
  • Boolean
    • Named after the mathematician George Boole, Boolean data type values are restricted to True and False. They are useful for recording data that can only take two values
  • Boolean
    • True
    • False
  • Representing Positive Integers in Binary
    Computers store whole numbers using binary. Each step in place represents a value of two times the previous place. A single binary digit is called a bit, and eight bits form a byte. Half a byte (four bits) is called a nybble
  • Binary to Decimal
    The least significant bit is the one furthest to the right, while the most significant bit is furthest to the left. When representing positive integers, the least significant bit represents a value of 1, with the 2nd least significant bit representing a value of 2, then 4, 8, etc. To convert, multiply the digit by its place value and add to a total
  • The binary number 1101 is 13 in decimal
  • Decimal to Binary conversion
    Find the largest power of two smaller than the number, write out place values in powers of two up to this power, place a 1 or 0 in each position so that the total adds up to the number
  • Binary Addition rules
    1. 0 + 0 + 0 = 0
    2. 0 + 0 + 1 = 1
    3. 0 + 1 + 1 = 10
    4. 1 + 1 + 1 = 11
  • Binary numbers can be represented as a whole number of bytes by adding leading zeros without affecting the value
  • 47 in binary with leading zeros to represent a byte is 00101111
  • Binary addition
    Starting from the least significant bits, add the values in each column and place the total below
  • Binary addition
    If the result of addition for a single column is more than one digit, place the first digit of the result in small writing under the next most significant bit’s column
  • Binary addition
    If there is a 0, a 1, and a small 1 in a column, the result is 10. Write the 1 in small writing under the next most significant bit’s column
  • Binary addition
    If there are three 1s in a column, the result is 11. Write the first digit of the result under the next most significant bit’s column
  • Binary addition
    Read off the result from the full-size numbers at the bottom of each column
  • After carrying out binary addition, it’s a good idea to check your answer by converting to decimal if you have time
  • Binary can represent negative numbers using different methods
  • Sign Magnitude representation is a way to represent negative numbers in binary by adding a leading 1 for negative numbers and a leading 0 for positive numbers
  • In Sign Magnitude representation, a leading 1 indicates a negative number and a leading 0 indicates a positive number
  • Converting from Sign Magnitude to decimal involves noting the most significant bit, remembering the sign, discarding the leading bit, converting the remaining bits to decimal, and adding the sign
  • In Two’s Complement representation, binary arithmetic with negative numbers is facilitated
  • Two’s complement makes binary arithmetic with negative numbers much more simple
  • Two’s complement
    Makes the most significant bit negative to represent negative numbers in binary
  • Converting to two’s complement
    Flip all bits in the positive version of a binary number and add one
  • Converting to two’s complement
    • Example: 00000111 -> 11111000 -> 11111001
  • Values in a binary byte
    • -128
    • 64
    • 32
    • 16
    • 8
    • 4
    • 2
    • 1
  • Calculating the equivalent of a binary byte in decimal using the method explained earlier
  • Two’s complement makes subtraction in binary easy by subtracting a number from another as adding a negative number
  • In five bit two’s complement, 8 is 01000 and -12 is 10100
  • Adding two’s complement numbers
    Use the technique for adding explained earlier before reading off the result
  • Checking the result of adding two’s complement numbers
  • Hexadecimal is base 16, using characters A-F to represent 10-15