Skip to Content.
Sympa Menu

freetds - RE: money wire format

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Thompson, Bill D (London)" <ThompBil AT exchange.uk.ml.com>
  • To: "'TDS Development Group'" <freetds AT franklin.oit.unc.edu>
  • Subject: RE: money wire format
  • Date: Thu, 8 Aug 2002 07:17:41 +0100


james,

I guess what I was trying to say is this :

consider a money value of 1.
This is represented by two 4 byte integers, each independently big or little
endian.

On bigendian they would be:

0 0 0 0 0 0 0 1

which, if you were to cast the data to an 8 byte integer would make sense.


On little endian the two bytes would be:

0 0 0 0 1 0 0 0

which, if you were to cast the data to an 8 byte integer would NOT make
sense (well it would , but the number would be wrong). The number 1 , on a
little endian machine in an 8 byte integer would presumably be:

1 0 0 0 0 0 0 0

HTH, How did you get on ?

Bill


> -----Original Message-----
> From: James K. Lowden [SMTP:jklowden AT schemamania.org]
> Sent: Thursday, August 08, 2002 1:59 AM
> To: TDS Development Group
> Subject: [freetds] RE: money wire format
>
> On Wed, 7 Aug 2002 23:13:11 +0100, "Thompson, Bill D (London)"
> <ThompBil AT exchange.uk.ml.com> wrote:
>
> > On a big endian machine the two 4 byte integers, strung together , can
> > be treated as a single entity.
> > On little endian of course they cannot.
>
> Of course? I guess I don't understand what "strung together" means. :)
> We can do 64-bit integer math. Does that count?
>
> > Assuming we dont change tds_process_row,
>
> But we probably should ...
>
> > and the money value comes down
> > unchanged the bytes would have to be moved as follows ( I reckon, and it
> > IS late here )
> >
> > Wire:
> >
> > 1 2 3 4 5 6 7 8
> >
> > To:
> >
> > 5 6 7 8 1 2 3 4
> >
> > does that make sense ?
>
> Thanks, Bill. It makes sense, except that I was expecting:
>
> 8 7 6 5 4 3 2 1
>
> (assuming each digit represents one byte). That's what you get with:
>
> char buf[] = "12345678";
> int i = tds_swap_bytes( buf, 8 );
> printf( "%d bytes swapped: \"%s\"\n", i, buf );
>
> I also experimented with ntohl and htonl, program below. The output:
>
> $ gcc -g -o swaptest swaptest.c
> $ ./swaptest
> 8 bytes input: "12345678"
> 8 bytes swapped: "87654321"
> 8 bytes reverted: "12345678"
>
> ntohl, input: "1234"
> ntohl, output: "4321"
> htonl, output: "1234"
>
> I wonder what "htonll" would do?
>
> I'll mangle a few and see how it goes.
>
>
>
>
> ---
> You are currently subscribed to freetds as: [thompbil AT exchange.uk.ml.com]
> To unsubscribe, forward this message to
> $subst('Email.Unsub')





Archive powered by MHonArc 2.6.24.

Top of Page