next up previous [pdf]

Next: Histogram equalization Up: Homework 1 Previous: Prerequisites

Digital representation of numbers

You can either write your answers to theoretical questions on paper or edit them in the file hw1/paper.tex. Please show all the mathematical derivations that you perform.

  1. UT's official ``burnt orange'' color is expressed by code #BF5700, where each pair of symbols (BF, 57, and 00) refers to a hexadecimal (base 16) representation of the RGB (red, green, and blue) components. Convert these numbers to an octal (base 8) and a decimal (base 10) representations.

  2. The C program listed below, when compiled and run from the command line, takes a string from the user and prints out the string characters. Modify the program to output ASCII integer codes for each character in the string. What is the ASCII code for the special new line character ``\n''?

    #include <stdio.h> /* for printf and scanf */
    
    int main(void)     
    {
        char *s, string[101];
    
        printf("Input a string: ");
        scanf("%100s",string);
    
        /* loop over characters */
        for (s=string; *s != ''; s++) 
    	printf("%c",*s);
    }
    

    Alternatively, modify the following Python script for the same task.

    string = input('Input a string: ')
    
    for char in string:
        print(char)
    
    

  3. In the IEEE double-precision floating-point standard, 64 bits (binary digits) are used to represent a real number: 1 bit for the sign, 11 bits for the exponent, and 52 bits for the mantissa. A double-precision normalized non-zero number $x$ can be written in this standard as

    \begin{displaymath}
x = \pm (1.d_1d_2{\cdots}d_{52})_2 \times 2^{n-1023} 
\end{displaymath}

    with $1 \le n \le 2046$, and $0 \le d_k \le 1$ for $k=1,2,\ldots,52$. What is the largest number that can be expressed in this system?

  4. The C program listed below tries to compute the machine epsilon: the smallest positive number $\epsilon$ such that $1+\epsilon > 1$ in double-precision floating-point arithmetic.

    1. Add the missing part of the program so that, when compiled, it runs without an assertion error.
    2. Modify the program to find the machine epsilon for single-precision floating-point arithmetic.

    #include <assert.h> /* for assert */
    #include <float.h>  /* for DBL_EPSILON */
    
    int main(void)
    {
        int i;
        double eps, one;
    
        eps = 1.0;
        for (i=0; i < 100; i++) {
    	eps /= 2;
    	one = 1.0+eps;
    
    	/* !!! INSERT SOMETHING HERE !!! */
        }
    
        assert(DBL_EPSILON==eps);
    }
    

    Alternatively, modify the following Python script for the same task.

    import numpy as np
    
    eps = np.float64(1.0)
    for i in range(100):
        eps /= 2
        one = eps+1.0
    
        # INSERT SOMETHING HERE
    
    DBL_EPSILON = np.finfo(np.float64).eps
    assert(DBL_EPSILON == eps)
    


next up previous [pdf]

Next: Histogram equalization Up: Homework 1 Previous: Prerequisites

2022-08-24