Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

IEEE conversion problem - code

pascal ieee

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1 CNB567

CNB567

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 26 June 2014 - 10:03 AM

Hi guys!

 

I am not all that good with pascal so I need some help.

The program I am writing should convert decimal to IEEE in single precision.

I know that there are some 'dirty' ways to do conversions in C, so there must be a way to do it in Pascal. I've been searching documentation and can't really find anything (I may be looking in a wrong place) so here I am - asking. Would you know how does it work in Pascal? Is there any 'dirty' way of 'stripping' the given number (here: real) and extracting all that I need from it to make the conversion (like I would do in assembly language for example?)?? I would SO appreciate any clue in the subject.

 

Thanks,

CNB



#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 26 June 2014 - 10:24 AM

I would probably just create a single precision variable and then assign the value to it. With that said, that will only make it single-precision IN MEMORY. What is your intention after that? Do you need it in a file, in a database, displayed onscreen, etc?


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 CNB567

CNB567

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 26 June 2014 - 10:47 AM

I just need it on a screen, it doesn't has to be stored anywhere.



#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 26 June 2014 - 10:54 AM

Do you need the binary representation onscreen, or the decimal representation? Gotta love details :)


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 CNB567

CNB567

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 26 June 2014 - 12:25 PM

:)  Nothing wrong with that.

No, don't need anything else but the IEEE representation on the screen.

I know, it seemed pretty basic to me as well when I first heard of it, but then I sat down to write a code... ;)



#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 27 June 2014 - 04:30 AM

My first thought was how I'd do this in C: get a pointer to the single-precision float, cast the pointer to an int pointer, and then do bitwise comparisons to extract each bit as a 1 or 0 and add those to a string.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 CNB567

CNB567

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 27 June 2014 - 05:10 AM

that's some decent idea. could actually work and wouldn't require million procedures. I'll try it this way. Thanks.