View previous topic :: View next topic |
Author |
Message |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Wed Sep 29, 2004 2:38 pm Post subject: Putting 6 numbers in a char(2) field |
|
|
Hi,
Is there anyway to store 6 numbers in a char(2) field by converting the number to hex or binary? |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Wed Sep 29, 2004 4:52 pm Post subject: |
|
|
whizkid79,
What is the max and min value you want to store in the 6 byte field?
max = +999,999
min = -999,999
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Frank Yaeger Sort Forum Moderator

Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
|
Posted: Wed Sep 29, 2004 5:03 pm Post subject: |
|
|
You're going to need quite a shoehorn to get a 6 digit value into a 2-byte binary field since the maximum positive 2-byte binary value is X'FFFF' = 65535 = 5 digits. _________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort |
|
Back to top |
|
 |
whizkid79 Beginner

Joined: 29 Sep 2004 Posts: 53 Topics: 14
|
Posted: Wed Sep 29, 2004 6:16 pm Post subject: |
|
|
yes. only positive numbers.
max = +999,999
I know it is impossible. Just checking whether there is a way or not. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Wed Sep 29, 2004 7:04 pm Post subject: |
|
|
whizkid79,
As far as I know I don't think it is possible to store that number in 2 bytes.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Mike Chantrey Intermediate
Joined: 10 Sep 2003 Posts: 234 Topics: 1 Location: Wansford
|
Posted: Mon Oct 04, 2004 7:59 am Post subject: |
|
|
It depends...
It's not really possible in the general case for 'random' data which is distributed across the full range of values, since you can't have more than 65536 *different* values in 2 bytes, but that doesn't necessarily mean you can't store 999999 as a coded value in two bytes. Suppose for example that your data contains less than 65536 distinct values, then you can have an encoding scheme where each of these distinct values was encoded as a number from 0-65535 via a translation table. This table is a one off fixed overhead, and each data value can then be stored as two bytes.
Real data often has 'holes' - values that never occur - so you might be able to use this feature as above.
Or suppose that the data has some sort of pattern to it (non-random). The less randomness the data contains the more it can be compressed - to take it to extremes, a file containing 200 letter 'A's can be easily compressed to x'240'+'A' (i.e. to 1% of its length). So if your data as a whole was very non-random you could get something like PKZIP to compress it to an *average* of less than 2 bytes per 6-digit number. But this is for an entire file, not a specific field. |
|
Back to top |
|
 |
Mike Chantrey Intermediate
Joined: 10 Sep 2003 Posts: 234 Topics: 1 Location: Wansford
|
Posted: Mon Oct 04, 2004 8:01 am Post subject: |
|
|
Correction: x'240' above should read x'C8' = decimal 200 |
|
Back to top |
|
 |
|
|