Math

D

DaveP

hi all.....
i have Transaction ids 1000000 or greater in size

i want to do a math computation to represent any number in smaller digits...

example
838 some math function(s) would calculate back to starting number

starting number 18347868 calculate some math to smaller number and then
back

TIA
DaveP
 
J

Jon Skeet [C# MVP]

DaveP said:
i have Transaction ids 1000000 or greater in size

i want to do a math computation to represent any number in smaller digits...

example
838 some math function(s) would calculate back to starting number

starting number 18347868 calculate some math to smaller number and then
back

Well, you could just take away 10000000... beyond that, we'd know more
information about what the IDs could be. Doing it just with maths, you
quickly run into the pigeon-hole principle:

http://en.wikipedia.org/wiki/Pigeonhole_principle
 
N

Nicholas Paldino [.NET/C# MVP]

DaveP,

The only way you are going to be able to get a smaller number in terms
of how many characters it takes up is going to be by changing the
representation of the number to a number in a system where the base is higer
than 10 (which is what you are using now). For example, your number in base
10, 18347868, would be represented in hexidecimal as:

117F75C

Which is one character shorter. You can increase it to 26, and maybe
get a greater compression (using characters a-z in the alphabet) or maybe 36
(using a-z, 0-9) or even 62 (a-z, A-Z, 0-9).

However, this is going to produce a string, so in terms of bytes, you
are going to use more bytes than you would storing it in four bytes in an
integer.
 
R

rossum

hi all.....
i have Transaction ids 1000000 or greater in size

i want to do a math computation to represent any number in smaller digits...

example
838 some math function(s) would calculate back to starting number

starting number 18347868 calculate some math to smaller number and then
back

TIA
DaveP
I am not quite clear what it is you want to do. I have two
suggestions that might, or might not, be what you want.

1. Purely to compress the string representation of the number you
could use Binary Coded Decimal (BCD) This packs two decimal digits
into a single byte, so your 1000000 would take up four bytes in packed
BCD. For example your 18347868 -> { 0x18 0x34 0x78 0x68 } in BCD,
four bytes.

2. If you want to reduce the actual size of the numbers used
internally then pick a reasonable sized prime number, like 1019, and
make all your Transaction IDs multiples of that number. Just store
T_ID / 1019 and multiply when you need to restore the full Transaction
ID.

T_ID Internal Representation
18347095 18005
18348114 18006
18349133 18007
18350152 18008

This means that you cannot use every possible Transaction ID, your
18347868 is not allowed for instance because it is not a multiple of
1019. If this is a problem for you then do not use this method.

rossum
 
D

DaveP

What it is im doing..is piggy backing on another number imcomming from the
outside world
this number is then sent to another company
now where my number is concatenated to the end of the cust incomming ID+MYID
The resulting string is to large for the Data Implementation

used for return reporting to identify the incomming customer prior
transaction , the myid part is our transaction id

Tks
DaveP
 
R

rossum

What it is im doing..is piggy backing on another number imcomming from the
outside world
this number is then sent to another company
now where my number is concatenated to the end of the cust incomming ID+MYID
The resulting string is to large for the Data Implementation

used for return reporting to identify the incomming customer prior
transaction , the myid part is our transaction id

Tks
DaveP

Two suggestions:

1 Just use as many least significant digits of the incoming ID as you
can and hope that your ID is enough to distinguish where the truncated
numbers match.

2 You need a bigger data field.

rossum
 
D

DaveP

i think im screwd...
this field is a must at 20 max characters cant change
its a hl7 definition
i'll come up with somthing...
thanks alot for all the help
DaveP
 
F

Fred Mellender

Could you express myID in hexadecimal before concatenating (I assume myID is
numeric). That will take fewer digits. The receiving application can
recover the original myID when it needs it.

Of course you could use a higher base than 16 (e.g. 34, using 0-1, A-Z, or
even higher using all printable characters).
 
R

rossum

i think im screwd...
this field is a must at 20 max characters cant change
its a hl7 definition
i'll come up with somthing...
thanks alot for all the help
DaveP
Would it be easier to add a new field rather than change an existing
one?

rossum
 
D

DaveP

im not in charge of that...this is a specification of ansi edi
transactions..this acct number is 20 characters.
So im trying to figure out a way to piggy back on a incomming acct no...with
our Trans Number
id.....

Thanks Alot
DAVEP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top