Functions
testField.c File Reference

Driver to test functions of field.c (do not modify) More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "field.h"

Functions

void printBinaryMSB (int value, int msb)
 
void printBinary (int value)
 
static void usage ()
 
static void printResult (int result)
 
static int getArg (char *arg)
 
int main (int argc, char *argv[])
 

Detailed Description

This is a driver program to test the functions defined in field.h and implemented in field.c. The program takes one or more command line parameters and calls one of the methods, then prints the results. To see how to use the program, execute testField in a terminal window. This will print a usage statement defining how to run the program. The first parameter of the program is always a key defining which function to run. The options are:

A sample execution might be: testField get 0xABCD 9 4 0

which prints

dec: 60  hex: 0x3C  bin: 0000-0000-0000-0000-0000-0000-0011-1100

All values may be entered as signed decimal numbers or as hex values by beginning it with 0x, or as binary numbers by beginning with 0b.

Author
Fritz Sieker

Function Documentation

static int getArg ( char *  arg)
static

Get int value from argument, allowing binary input like 0b0111001

Parameters
argstring containing value (decimal, octal, hex, binary)
Returns
value
int main ( int  argc,
char *  argv[] 
)

Entry point of the program

Parameters
argccount of arguments, will always be at least 1
argvarray of parameters to program argv[0] is the name of the program, so additional parameters will begin at index 1.
Returns
0 the Linux convention for success.
void printBinary ( int  value)

Print a 32 bit binary representation of a value.

Parameters
valuethe value to be printed
void printBinaryMSB ( int  value,
int  msb 
)

Print the binary representation of a value starting at the specified bit position. A separator is printed every 4 bits for easy reading.

Parameters
valuethe value to be printed
msbthe bit position to begin printing (31 to 0)
static void printResult ( int  result)
static

print the value in decimal, hex and binary.

Parameters
resultthe value to be printed.
static void usage ( )
static

Print a usage statement, then exit the program returning a non zero value, the Linux convention indicating an error