Ch 2. Internal Data Representation of Characters, Integers, Real Numbers
Ch 2. Programming Exercises
Exercise 1: Character Encoding Converter
The objective of this exercise is to practice working with character encodings. Your task is to write a program (using pseudocode or a programming language of your choice) that takes a string input and outputs the ASCII and Unicode code points for each character. In addition, there should be support for converting between UTF-8 and UTF-16 encodings.
Exercise 2: Integer Representation Simulator
The objective of this exercise is to understand binary representations of signed integers. Your task is to create a program (using pseudocode or a programming language of your choice) that accepts a decimal integer and displays its binary representation in:
- Unsigned format
- Sign-magnitude
- One’s complement
- Two’s complement
Include overflow detection for fixed bit-widths (e.g., 8-bit, 16-bit).
Exercise 3: Floating-Point Encoder
The objective of this exercise is to explore the IEEE 754 floating-point format. Your task is to write a program (using pseudocode or a programming language of your choice) that takes a decimal number and outputs its IEEE 754 single-precision binary representation. Include a decoder that converts the binary back to decimal.
Exercise 4: Memory Viewer Tool
The objective of this exercise is to simulate how data is stored and interpreted in memory. Your task is to build a tool (using pseudocode or a programming language of your choice) that accepts a 32-bit binary string and allows the user to interpret it as:
- An unsigned integer
- A signed integer
- A floating-point number
- A character array
Add support for endianness (big-endian vs little-endian).
Exercise 5: Sensor Data Logger
The objective of this exercise is to combine multiple data types in a real-world context. Your task is to simulate a smart device (using pseudocode or a programming language of your choice) that logs:
- Device ID (hex)
- Temperature (float)
- Status (Boolean)
- Timestamp (binary)
Store each log entry as a tuple and print a formatted summary of the data.