b16_set_exponent

I was asked how to set the fields of the binary16 number. This is the same as in homework 2, only it is easier because you don't have to mask to an integer to do bitwise operations on a binary16 number.

code format="c" void b16_set_exponent(binary16 *b; int exp) { binary16 rep; rep = (binary16) exp + 15; /* deal with -15 offset */ rep <<= 10;                 /* shift over to the correct spot */ *b &= 0x83FF;               /* set the exponent field to all zeros */ *b |= rep;                  /* put the new representation in */ } code

This function may not be convenient to actually use, but it should give you a good idea of how to work with the fields.