Jump to content

OT: C programming


lokidecat

Recommended Posts

  • Members

Anyone really good at C Programming? My GF is hitting a wall and she's frustrated with a class and I'm trying to help her.

 

It's a bit out of my realm and was wondering if someone can explain this in a way that isn't 100% over my head.

 

Basically it deals with IEEE754 floating point numbers, and converting them.

 

i'm not asking to do her homework for her, but if someone has a cool way of explaining this that'd be cool.

 

She has to have the program accept user input, then print them out like this:

First line: integer, right justified in a 10 char field

then HEX representation of the integer

 

second line: floating, right justified in a 10 char field, with 2 digits to the right of the decimal.

Then HEX representation of the integer.

 

 

her biggest hang up is converting Float to HEX right now. I've scoured the internet and they talk about multiplying by 16 .. and whatnot.

 

I need a "For Dummies" book on IEEE754 float notation

 

you know. SEEEEEEEEMMMMMMMMMMMMMM etc... crap

Link to comment
Share on other sites

  • Members

Ok, take this with a grain of salt - I'm an expert programmer; I know C but don't actively use it, but I don't see how the language is all that relevant anyway. I guess I don't get the question. Why wouldn't you just look up the standard, determine the data format, and figure out how to put it into whatever format you want it in?

 

It looks to me like the Wikipedia article ought to have everything you need: http://en.wikipedia.org/wiki/IEEE_754

Link to comment
Share on other sites

  • Members

This mostly does what is required. Sorry, the indenting was removed by the posting.

#include

main()
{
char buf[256];
int i;
float f;

/* get something from the console */
gets(buf);

/* convert string to int */
sscanf(buf, "%d", &i);

/* convert string to float */
sscanf(buf, "%f", &f);

/* do the int thing */
printf("% 10d 0x%x", i, i);

/* and the float thing */
printf("%10.2f 0x%x", f, i);
}

Link to comment
Share on other sites

  • Members

 

her biggest hang up is converting Float to HEX right now. I've scoured the internet and they talk about multiplying by 16 .. and whatnot.

 

 

printf already does this with the proper formatting parameter, as misterhinky used. You could also just cast it.

Link to comment
Share on other sites

  • Members

Present her with a uke.

 

A 50's plastic one. Island colors.

 

It's about as relevant.

 

(Unless she's Indian (the tea drinking ones) ), with access to a media "centre".

 

Or, in the only other precept this seems to apply:

C is shorthand when dealing with a growing segment of our population: the Hispanics, as in "C, I speak No Inglish".

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...