Re: bytes_to_int

new topic     » goto parent     » topic index » view thread      » older message » newer message

your average Joe wrote:
> 
> Hi,
> 
> I seem to be having a problem reading in from an array of stored values and
> 
> using the bytes_to_int function.
> 
> A massive chunk of the data i read in is stored in 2 byte sequences so what
> i do is use the algorithm
> 
> object void
> for i = 1 to length(array) do
> 
>     if length(array[i] = 2) then
> 
>        void = append(array[i],0)
>        void = append(array[i],0) 
> 
>     end if 
> 
> end for
> 
> * this sets up the array so that i can read a 4 byte sequence into the
> bytes_to_int
> function.
> 
> * will padding the 2 byte sequence with two zeros so that i can pass it to the
> bytes_to_int 
> function alter the real value returned ?
> 
> * it seems to work fine for a majority of the data i pass, but it seems the
> value is distorted 
> once it gets to a certain magnitude.
> 
> * is there another way of padding a 2byte sequence so that it can be read
> unaltered
> by bytes_to_int?
> 
> thanx,
> Joe.

Hi there Joe,


Here's something that works...


--start of file--------------------------

include misc.e
include machine.e

sequence array,intbytes

array={{1,2},{3,4},{5,6}}
intbytes=repeat(0,length(array))

for i = 1 to length(array) do
    if length(array[i])=2 then
       --array[i]=reverse(array[i]) --(optional)
       array[i]=array[i]&{0,0}
       intbytes[i]=bytes_to_int(array[i])
    end if 
end for

?array
?intbytes

sleep(100)

--end of file----------------------------

Of course if you dont need to store the 4 byte values of array[i]
then you can use a dummy variable to hold the data and then
just convert it and store the resulting integer in 'intbytes'.

Just one last note...

Depending on the order of your two-byte data you may need to use
'reverse' to change the order before appending zeros (shown above
as 'optional'.



Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu