{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment1Sol

# Assignment1Sol - Question 4 Program Name toieee Function...

This preview shows pages 1–8. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question 4 /* Program Name: toieee Function: Outputs the IEEE 754 representation of a single precision floating point number entered on stdin. Usage: % toieee [float] Author: Julien Cassis Date: January 10, 2008 */ #include <stdio.h> int main(char argc, char *argv[]) { union { float floatnum; int intnum; } myunion; if (argc != 2) { printf("Usage: toieee [float]\n"); return(0); } sscanf(argv[1],"%g",&myunion.floatnum); /* g format is a superset of f */ printf("IEEE754(%g) = %08x\n",myunion.floatnum,myunion.intnum); return(0); } Output C:\Users\cassis\221\lcc>toieee -341.274 IEEE754(-341.274) = c3aaa312 C:\Users\cassis \221\lcc>toieee 6.02e23 IEEE754(6.02e+023) = 66fef4f9 C:\Users\cassis \221\lcc>toieee 3.4e38 IEEE754(3.4e+038) = 7f7fc99e C:\Users\cassis \221\lcc>toieee -3.4e38 IEEE754(-3.4e+038) = ff7fc99e C:\Users\cassis \221\lcc>toieee -3.072e-12 IEEE754(-3.072e-012) = ac582c3b
Question 5 /*----------------------------------------------------------------------*/ /* File Name: div32.c */ /* Description: A simple package to support binary division of long */ /* integers using the subtract and shift procedure. The */ /* main is a command line procedure for testing the */ /* div32 function which implements the algorithm. */ /* Author: F.P. Ferrie */ /* Date: September 12, 2002. */ /* Modified: January 25, 2008. */ /* Modifications: None */ /*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/ /* Includes */ /*----------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> /*----------------------------------------------------------------------*/ /* Defines /*----------------------------------------------------------------------*/ #define MSBLONG 0x40<<((sizeof(long)-1)*8) /* msb position long int */ #define DIV0 -1 /* return code for divide by zero */ #define SUCCESS 0 /* return code for success */

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 9

Assignment1Sol - Question 4 Program Name toieee Function...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online