One little endian question

Kenneth Brody kenbrody at bestweb.net
Sat Mar 1 08:41:25 PST 2008


Quoting Jeff Harrison (Fri, 29 Feb 2008 19:42:45 -0800 (PST)):

> I have a routine that I developed to convert 2 binary
> bytes of data from filepro's key header into a date
> that filepro can understand.  I know that sounds
> strange, but this is needed, I think, since I'm using
> an alien filepro file to map to a key file in order to
> check  for data integrity issues.
>
> My routine is shown below - I will feed it the "1st"
> byte of the date in the x field, and the "2nd" one in
> the y field.
>
> ::dt1 = base(asc(x),"10","16"):
> ::dt2 = base(asc(y),"10","16"):
> ::longago = "01/01/1983":
> ::thedate = longago + base(dt1&dt2,"16","10"):

I don't understand why you convert to hex, concatenate the values, and then
convert ehm back to decimal, when you could simply multiply by 256 and add:

     longago = "01/01/1983"
     thedate = longago + ( asc(x)*"256" + asc(y) )

> ::'...:
> ::declare dt1(2):
> ::declare dt2(2):
> ::declare longago(10,mdyy/):
> ::declare thedate(10,mdyy/):
>
> As you may know, there is an endian issue with certain
> flavours of filepro running on certain boxes, where
> the binary order is reversed - I'm assuming all I will
> need to do in those cases is reverse dt1 and dt2 bytes
> in my "thedate" assignment.
>
> The question is, though, how will I know when I need
> to do the reversal?  Are there certain known values
> for @os where it is one way or the other?  Or is there
> a better way to do this?

Why not just use GET16() instead, which defaults to using native byte
order?

For example, let's assume that the 20 byte header is in the variable
"Header" and you want @UD:

     longago = "01/01/1983"
     thedate = longago + get16(Header,"6")

-- 
KenBrody at BestWeb dot net        spamtrap: <g8ymh8uf001 at sneakemail.com>
http://www.hvcomputer.com
http://www.fileProPlus.com


More information about the Filepro-list mailing list