My Project
Functions
field.h File Reference

Defines interface of field.c functions (do not modify) More...

Go to the source code of this file.

Functions

int getBit (int value, int position)
 
int setBit (int value, int position)
 
int clearBit (int value, int position)
 
int getField (int value, int hi, int lo, int sign)
 

Detailed Description

This file defines the interface to a C file field.c that you will complete. You will learn how to use the C language operators for binary and (&), binary or (|), and binary not (~). You will also use the C language bit shift operators (<< and >>).

Author
Fritz Sieker

Function Documentation

int clearBit ( int  value,
int  position 
)

Clear the specified bit in a value (make it equal to 0).

Parameters
valuethe source value or bit pattern
positionthe bit position to be set (0..31)
Returns
An integer value that is the original value with the specified bit cleared.
Todo:
Implement in field.c based on documentation contained in field.h
int getBit ( int  value,
int  position 
)

Get the specified bit from a value.

Parameters
valuethe source value or bit pattern
positionthe bit position to get (0..31)
Returns
1 when the bit is set, and 0 otherwise.
Todo:
Implement in field.c based on documentation contained in field.h
int getField ( int  value,
int  hi,
int  lo,
int  sign 
)

Extract the field between bits hi and lo (inclusive) and adjust it for the sign. This means that if sign = 1 (negative), you should return the 2's complement of the field. If sign = 0 (positive), you should return the field as-is. See the examples in the main instructions. This function will be very useful in P3 when you need to extract different parts of an IEEE number.

Parameters
valuethe source value or bit pattern
hithe bit position of the high end of the field. This parameter is guaranteed to be greater than or equal to lo.
lothe bit position of the low end of the field. This parameter is guaranteed to be less than or equal to hi.
sign0 (positive) means we want the field as-is. 1 (negative) means we want the 2's complement of the field.
Returns
The value of the field adjusted for the sign. See the examples in the main instructions.
Todo:
Implement in field.c based on documentation contained in field.h
int setBit ( int  value,
int  position 
)

Set the specified bit in a value (make it equal to 1).

Parameters
valuethe source value or bit pattern
positionthe bit position to be set (0..31)
Returns
An integer value that is the original value with the specified bit set.
Todo:
Implement in field.c based on documentation contained in field.h