Thread: any good ideas

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    55

    any good ideas

    Hi,

    Just a quick question. Is it possible (in any way) to compress a double into a smaller varaible. Say unsigned short etc. This to decrease the size of a struct with a few doubles in it. What i want to do is compress a struct and then be able to decompress it. I have given it a though and are playing with the idea of ecrypting (maybe?) and then decrypting to get the true value back. But i need some ideas (if this is possible) on what i should do?

    G'n'R

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Is it possible (in any way) to compress a double into a smaller varaible. Say unsigned short etc
    If the double values are actually integers in the range of unsigned short, then yes (and why aren't you storing them as such if this is so).

    Otherwise you will lose information when you truncate the value.

    > What i want to do is compress a struct and then be able to decompress it
    Unless this is a large structure, and you need to transmit it over a slow link, I see no point. Small amounts of binary data do not compress very well.

    If you encrypt it, you won't be able to compress it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    55
    Well the thing is... It is a large struct and i need doubles to store large values. However, i got limited storage area. I works now, but it would be a great advantage to make it smaller. Hence, the idea about maybe encrypting the values in the double with a special code to "compress" it and then using that code to "decompress" it when reading it back. e.g. Say i got 274877906943 in the double and then (here is where i need some good ideas) somehow (by division or something else) make that number smaller for storage for so turn it back into its true value later.

    Cheers
    G'n'R

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    doubles are typically stored like this
     1 sign bit
    10 exponent bits
    53 mantissa bits
    64 bits in total.

    Now, if you're saying that these doubles are effectively large integers, which contain less than 15 decimal digits ( 274877906943 is 12 digits) then you can pack these into 54 bits instead of 64 bits.

    A 12 digit number only needs 40 bits to accurately represent it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, there are 2 types of data compression, lossy and lossless.

    Lossy compression would be what you'd do if you converted each double to some smaller data type. A double has 64 bits, an unsigned short would have 16 bits, so many doubles would have to map to the same unsigned short -- meaning you couldn't prefectly reconstruct the original. Salem's suggestion is lossy, as well -- it would shorten the value by discarding the least significant bits. Most video and audio compression works like this.

    Lossless would let you perfectly reconstruct the original, but not all data could be compressed, and sometimes you actually make files larger by compressing. ZIP files are an example of lossless compression, they work by finding patterns in the data and saving the patterns instead of the raw data. Sparse matrices are very good candidates for lossless compression, as they contain many 0 values.
    Last edited by The V.; 10-29-2001 at 02:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Board ideas
    By neandrake in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 04-23-2009, 02:28 AM
  2. Ideas, how do you get them? xD
    By Akkernight in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-22-2009, 03:53 AM
  3. Project ideas
    By steve1_rm in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2008, 05:34 AM
  4. Programming ideas (probably the 1000th thread...)
    By Desolation in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2007, 11:08 PM
  5. gift ideas for girls
    By cozman in forum A Brief History of Cprogramming.com
    Replies: 95
    Last Post: 07-11-2002, 11:31 AM