Assignment1Sol

Assignment1Sol - Question 4 /* Program Name: toieee...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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 */
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/06/2010 for the course ENG ECSE221 taught by Professor Ferri during the Fall '09 term at McGill.

Page1 / 9

Assignment1Sol - Question 4 /* Program Name: toieee...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online