Defines interface of field.c functions (do not modify)
More...
Go to the source code of this file.
|
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) |
|
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
int clearBit |
( |
int |
value, |
|
|
int |
position |
|
) |
| |
Clear the specified bit in a value (make it equal to 0).
- Parameters
-
value | the source value or bit pattern |
position | the 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
-
value | the source value or bit pattern |
position | the 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
-
value | the source value or bit pattern |
hi | the bit position of the high end of the field. This parameter is guaranteed to be greater than or equal to lo. |
lo | the bit position of the low end of the field. This parameter is guaranteed to be less than or equal to hi. |
sign | 0 (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
-
value | the source value or bit pattern |
position | the 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