Thread: Portable Doubles

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #18
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by SlyMaelstrom
    Convert it to hexidecimal? If the system stores things as binary, it's going to store it as binary no matter how you wish to display it. It's not as if one hex digit fits in one binary digit therefor you can just convert everything to hex and save space. I don't think they're looking to just store a string directly, I think they want to maintain the same exact bytes. I'm honestly not sure what floating point looks like in hex, but I have a feeling it's representation would be only slightly shorter than just the decimal representation of the string.

    EDIT: For strings -- here is double precision in decimal vs hex
    Code:
    3.1415926535897930
    400921FB54442D18
    So two bytes. I suppose it shrinks it a bit, but I don't think it's small enough for what the OP wants.

    EDIT 2: ...and lastly, which I probably should have thought of first, isn't converting to hex on one comp and back on another subject to the same rounding errors as just sending the double directly would have?
    Actually 3.1415926535897930 as a character string will compress considerably more than you indicate, if each character is stored in an eight bit byte, there are 255 possibilities that could be used, however only 10 are being used, (0-9), so there is considerable reduncancy there. If you encode each character in 4 bits rather than 8, which you could you would halve the data length at a stroke. The character string 3.1415926535897930 would use 18 bytes the hexidecimal number 400921FB54442D18 only uses 8, so you have more than halved the transmission time, (44%).
    (I was programming im hexidecimal well before your were born!!, seriously, I started programming in machine code, you lot don't know you are born!!)
    Last edited by esbo; 08-30-2006 at 07:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. parse doubles from socket read?
    By willy in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:32 AM
  2. C - Portable?
    By vb.bajpai in forum C Programming
    Replies: 2
    Last Post: 07-15-2007, 09:09 AM
  3. sscanf with doubles
    By ufsargas in forum C Programming
    Replies: 1
    Last Post: 06-28-2006, 03:05 PM
  4. Replies: 3
    Last Post: 09-01-2005, 11:47 AM
  5. which Portable mp3 player?
    By Raihana in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 01-09-2004, 07:58 AM