Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to make a program to take in a binary input from the command line (as seen in the examples given), and output it

image text in transcribed

I need to make a program to take in a binary input from the command line (as seen in the examples given), and output it as a float value (using IEEE standard). If you could implement it as to work with the template that would be very nice. I am also required to use bit fields for the solution. Also comments in the code would be greatly appreciated. Thanks in advance.

Exercise #2: Build Float Values using Bit-fields and Unions You second taak is to implement a way of building float values by inputting an appropriate bit-pattern representing the number according to the IEEE standard. We have supplied a skeleton program that defines a union type conaiating of s 32-bit quantity that can be interpreted as either an unsigned int, an unsigned int that has been partitioned into three bit-fields, or as a float value. The program reads three bit- strings from the command-line, corresponding to the sign exp frac components of a floating point number, stores these values in the union, then displays the bit-strings from the union or debugging), and finally displays the contents of the union as a float value What you need to do is . devise an appropriate bit-field representation for floats that will allow you to easily access to components . complete the getBits) function, which takes bit-strings from the command-ine and stores them in the appropriate components in a Union32 object complete the shouBits() function, which converts the bit-strings for the three components of a floating point value in a Union32 object into a single C string, formatted as in the examples below Examples of how make a float should eventually work: gcc -Wall -Werror gcc -o maf make_a float.o -c-o make a float.o make a float.c Usage: /maf Sign Exp Frac maf: invalid Exp: 1 bits 18866880 8186686688868e86ea80688 float: 2.508e008000 bits 1 10366880 8108003068eaee0a00a8008 float 2.58e880080 Float: .8036688oe8 not really 8, but very close float: 1.7580688008 corvert three bit stins celready chackod) 3 include 4 include S #include 6 #include ire 15 1st to keep gcc happy 8 typedef uint32 t Ward; neu, bits.signzraw.bits.exp new.hits,fracRj igle hit ie new.hits 10 struct _float anert chur 'frac inta 2-bit value in e.hit // define bit fields for sign, exp and frac // obviously they need to be larger than 1-bit each // and may need to be defined in a different order unsigned int sign:l, exp:1, frac:1; corvert a 32-bit bit-seingin val irto asequence 16 typedef struct fleat Float32; 18 union _bits32 float fval; // interpret the bits as a float Word xval; interpret as a single 32-bit word FLoat32 bits; / manipulate individual bits elete it wher you have sxplenented the Function 23 typedef union _bits32 Union32; chicks caand Lir ar need at leest 3, and all sust be strings of 8/1 25 void checkArgs (int, char ) 26 Union32 getBits(char *, char char +); 27 char showBits(Word, char) 28 int ustBits(charint)h iF (argc 3 1 38 int main int argc, char argv) union _bits32 u; char out[s8]; 34 // here's a hint u.bits,sign u.bits.exp- u.bits,frac ; 36 38 39 48 / check connand-line args (all strings of /1 // kills program if args are bad checkArgs (argc, argv); 42 convert command-line args into components af a Float32 inside a Union32, and return tha union u-gatBits (argv[1], argv[2], argv]) e int juatsitaehar str, int len) if (strlen str)! len) return printf( "bits : print f("float : %s ", shouBits(u.xval,out)); %e'lerin., u.fval); 46 11e while ("str 48 49 50

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

9. System creates a large, diverse talent pool.

Answered: 1 week ago