# Lab 10 – Prelab

## Floating Point Data

In this lab we will be exploring the bit-level representation of floating point numbers. This will require you to correctly manipulate binary data (bits) in C and assembly. This prelab will help you practice these skills by solving the programming “puzzles” below. To make things a little more difficult you will have to solve each puzzle by only using a certain set of bit operations provided with each exercise. You cannot use loops (do, while, for) or conditional statements (if, case).

Although this lab is in C, you should re-read zyBook section 5.6 to review bitwise operations.

## Setup

The file ~cs206/Labs/Lab10/bits.c contains all of the code you will need for this prelab. Copy it to your local Lab10 directory and add it to git. You do not need to work on the mips machine for this, any Unix machine with gcc will do.

## Exercise 1: Get Byte

The get_byte function extracts a single byte from a 32-bit word. The function prototype looks like:

And the baseline implementation is:

Your goal is to implement get_byte so that it produces the same results as the baseline_get_byte function using ONLY bit-level operations, WITHOUT using a case statement (or if statements). Your get_byte should use bit mask operations (& and |) and bit shifts (<< and >>) to produce the same result. For more on bit manipulation check wikipedia (or a textbook).

## Exercise 2: Negate

Implement the negate function. You may not use the C negation operator (“-“) or conditional statements. You must manipulate the bits in the two’s complement number directly. Think about other ways you could negate a two’s complement number. Your function should match the results of baseline_negate.

## Exercise 3: Is Positive

Implement the is_positive function. Again you must find a bitwise expression to accomplish this. Hint: think about the logic needed for <=0 (i.e., is_negative_or_zero) and then invert this logic. Your function should match the results given by baseline_is_positive.

## Exercise 4: Tmin and Tmax

Implement the tmin and tmax functions. These compute the smallest (most negative) and largest two’s-complement numbers that can be represented by n bits.

## Exercise 5: Floating point min and max

The maximum value that can be expressed using IEEE754 single-precision floating point format  is  (2-2^-23)*2^127 (approximately 3.4028235e+38). The smallest positive value is 2^-126 (approximately 1.1754944e-38). Create the file prelab.txt and in it clearly describe the process used to arrive at these numbers. Then, derive the same values (maximum and minimum positive) for the IEEE754 double precision floating point format.

Submission

Once you complete the work, add, commit, and push the file bits.c to your git repo.