Practice exercise -- Data Representation Two's Complement for representing negative binary numbers: Method: take a positive binary number, invert the bits and add 1. For example, to find -2 start with 00000010 invert 11111101 add 1 00000001 -------- -2 = 11111110 1. Represent 5 as an 8-digit binary number. 2. Subtract a binary 5 from a binary 9: Method: convert 9 to an 8-bit binary number, find two's complement of positive binary 5, then add the two binary numbers. Text Compression: 3. Keyword Encoding. Replace frequently used words found in a text document with a single character. A chart: Original text(by Richard Stallman): Word Symbol My work on free software is motivated by an idealistic an ~ goal; spreading freedom and cooperation. and # by $ is % on ^ Richard's sentence encoded would be: What is the compression ratio? ____ (encoded length / original length) 4. Run-length encoding. A sequence of repeated characters is replaced by a flag character(e.g. *), followed by the repeated character(e.g.A), followed by a digit(e.g. 7) indicating how many times the character is repeated. The code *A7 would be decoded as AAAAAAA; and the compression ratio would be 3/7. How would the following string of characters be represented with run-length encoding? AAAALLLiiiiionnnnnn is king. What is the compression ratio? 5. Huffman Encoding. Variable length bit strings are used to encode each character. And no bit string is the prefix of any other string An encoding table: Code Character 00 A 11 E 010 T 0110 C 0111 L 1000 S Decode this string: 1101110001011 Encode SLEET