1. bytes_to_int
- Posted by your average Joe <spent_memory at hotmail.com> Feb 08, 2006
- 524 views
what is the highest floating point the Eu, bytes_to_int function can return?
2. Re: bytes_to_int
- Posted by Larry Miller <larrymiller at sasktel.net> Feb 08, 2006
- 497 views
your average Joe wrote: > > what is the highest floating point the Eu, bytes_to_int function can return? The bytes_to_int function returns a 32 bit unsigned integer, thus it's largest value will be #FFFFFFFF or 4294967295. Larry Miller
3. Re: bytes_to_int
- Posted by your average Joe <spent_memory at hotmail.com> Feb 08, 2006
- 487 views
that is reakky strange, because that is the number my bytes to int function resets at i cant go larger than 42.94967295 note the decimal place, thats were it cuts and goes back to zero + the remainder
4. Re: bytes_to_int
- Posted by Greg Haberek <ghaberek at gmail.com> Feb 08, 2006
- 495 views
- Last edited Feb 09, 2006
> i cant go larger than 42.94967295 You can't use bytes_to_int() for floating-point numbers, silly! They're not integers! You need to use float32_to_atom() or float64_to_atom() to convert bytes into floating-point numbers. ~Greg
5. bytes_to_int
- Posted by your average Joe <spent_memory at hotmail.com> Feb 12, 2006
- 493 views
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.
6. Re: bytes_to_int
- Posted by your average Joe <spent_memory at hotmail.com> Feb 12, 2006
- 492 views
basically, how can i convert a sequence like this sequence = {199,235} into a 2 byte signed integer
7. Re: bytes_to_int
- Posted by Evan Marshall <1evan at sbcglobal.net> Feb 12, 2006
- 486 views
your average Joe wrote: > > basically, how can i convert a sequence like this > > sequence = {199,235} > > into a 2 byte signed integer Doesn't
integer int sequence = {199,235} sequence = {199,235,0,0} int = bytes_to_int(sequence) bytes_to_int(sequence)
work? I get 60359.
8. Re: bytes_to_int
- Posted by Evan Marshall <1evan at sbcglobal.net> Feb 12, 2006
- 479 views
Evan Marshall wrote: > > your average Joe wrote: > > > > basically, how can i convert a sequence like this > > > > sequence = {199,235} > > > > into a 2 byte signed integer > > > Doesn't > > }}} <eucode> > integer int > sequence = {199,235} > sequence = {199,235,0,0} > int = bytes_to_int(sequence) > bytes_to_int(sequence) > </eucode> {{{ > > work? > > I get 60359. or rather
sequence seq integer int seq = {199,235} seq = {199,235,0,0} int = bytes_to_int(seq) >
9. Re: bytes_to_int
- Posted by your average Joe <spent_memory at hotmail.com> Feb 12, 2006
- 483 views
yes i have been using that method, and as far as i can tell, there seems to be some sort of clipping going on. by clipping i mean once i reach a certain magnitude it is not converting properly, if that makes sense. i can see it visually because i am mapping the returned values into a heightfield in opengl and they are all clipped at the exact same height so the tops of the hills at a certain elevation appear in the right spot x,z wise but appear below the other terrain points that arent clipped. The only thing i can trace it back to is this method of using {0,0} padding to convert them, note that the tops of the hills elevation wise map propely they just all have the same negative clipped magnitude
10. Re: bytes_to_int
- Posted by Bernie Ryan <xotron at bluefrog.com> Feb 12, 2006
- 485 views
your average Joe wrote: > > yes i have been using that method, and as far as i can tell, there seems to > be > some sort of clipping going on. by clipping i mean once i reach a certain > magnitude it is not converting properly, if that makes sense. i can see it > visually because i am mapping the returned values into a heightfield in opengl > and they are all clipped at the exact same height so the tops of the hills at > a certain elevation appear in the right spot x,z wise but appear below the > other > terrain points that arent clipped. The only thing i can trace it back to is > this method of using {0,0} padding to convert them, note that the tops of the > hills > elevation wise map propely they just all have the same negative clipped > magnitude Why don't you put a temporary check in the code where you are appending the 2 zeros to print an error if any byte in your 4 byte sequence exceeds the 256 size limit ? Bernie My files in archive: motor.eu w32engin.ew mixedlib.e eu_engin.e win32eru.exw Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
11. Re: bytes_to_int
- Posted by Al Getz <Xaxo at aol.com> Feb 12, 2006
- 487 views
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"
12. Re: bytes_to_int
- Posted by Jason Gade <jaygade at yahoo.com> Feb 12, 2006
- 495 views
Evan Marshall wrote: > > Evan Marshall wrote: > > > > your average Joe wrote: > > > > > > basically, how can i convert a sequence like this > > > > > > sequence = {199,235} > > > > > > into a 2 byte signed integer > > > > > > Doesn't > > > > }}} <eucode> > > integer int > > sequence = {199,235} > > sequence = {199,235,0,0} > > int = bytes_to_int(sequence) > > bytes_to_int(sequence) > > </eucode> {{{ > > > > work? > > > > I get 60359. > > > or rather > }}} <eucode> > sequence seq > integer int > > seq = {199,235} > seq = {199,235,0,0} > int = bytes_to_int(seq) > > </eucode> {{{ Actually, I think he wants to create a signed 16-bit integer. I'm not testing this, but here is how I would do it:
-- tested -- takes a two-element sequence in low-byte/hi-byte order -- and returns a signed 16-bit integer function bytes_to_short(sequence bytes) integer short if length(bytes) < 2 then if length(bytes) < 1 then short = 0 -- empty sequence else short = bytes[1] end if return short end if short = bytes[1] + 256 * bytes[2] if short > #7FFF then -- change sign short = and_bits(not_bits(short) + 1, #FFFF) short = -short end if return short end function -- bytes to short ? bytes_to_short({127}) -- 127 ? bytes_to_short({255, 127}) -- 32767 ? bytes_to_short({0, 128}) -- (-1) ? bytes_to_short({255, 255}) -- (-32768)
More error checking could be added, such as making sure each element of bytes is not greater than 255 (or using and_bits(bytes, #FF)). You could also change this to take longer sequences and break them into two, or (easily enough) take an atom and convert it to a 16-bit signed integer, etc. If you need to reverse the byte-order, then just switch this statement:
short = bytes[1] * 256 + bytes[2]
HTH -- "Any programming problem can be solved by adding a level of indirection." --anonymous "Any performance problem can be solved by removing a level of indirection." --M. Haertel j.
13. Re: bytes_to_int
- Posted by Evan Marshall <1evan at sbcglobal.net> Feb 12, 2006
- 480 views
Using this code:
atom fn fn = open("Results.txt","w") for x = 0 to 255 do for y = 0 to 255 do printf(fn,"%d\n",bytes_to_int({y,x,0,0})) end for end for
gives a file listing all integers from 0 to 65535
14. Re: bytes_to_int
- Posted by Jason Gade <jaygade at yahoo.com> Feb 12, 2006
- 486 views
your average Joe wrote: > > basically, how can i convert a sequence like this > > sequence = {199,235} > > into a 2 byte signed integer With the code I posted previously, I got -5177. Is that what you are looking for? -- "Any programming problem can be solved by adding a level of indirection." --anonymous "Any performance problem can be solved by removing a level of indirection." --M. Haertel j.
15. Re: bytes_to_int
- Posted by your average Joe <spent_memory at hotmail.com> Feb 12, 2006
- 486 views
Aha, thx for all the replies, lots of ideas and food for thought there, exactly what i needed :) I just noticed exactly where i am having the problem by slowing my converter and printing each one in all its forms so i can see what's happening. It is apparent to me now that the sequence {6,0} is suppose to return a value higher than 65535, that's exactly where i am getting the clipping problem on all elevations once that exceed that number which to my undestanding is the max i can output using the 2byte padding technique. Ill try the methods listed and let you know if i can get it working Thanks Joe
16. Re: bytes_to_int
- Posted by Jason Gade <jaygade at yahoo.com> Feb 12, 2006
- 476 views
your average Joe wrote: > > Aha, thx for all the replies, lots of ideas and food for thought there, > exactly > what i needed :) > > I just noticed exactly where i am having the problem by slowing my > converter and printing each one in all its forms so i can see what's > happening. > > It is apparent to me now that the sequence {6,0} is suppose to return a value > higher than 65535, that's exactly where i am getting the clipping problem on > all elevations once > that exceed that number which to my undestanding is the max i can output using > the 2byte padding technique. > > Ill try the methods listed and let you know if i can get it working > > Thanks > Joe Glad to help. What exact range and byte-order are you looking for? In an earlier post, you said you needed to convert them to 16-bit signed integers. What is the actual min and max output that you need? Do the 16-bit numbers need to be scaled to 32-bits? -- "Any programming problem can be solved by adding a level of indirection." --anonymous "Any performance problem can be solved by removing a level of indirection." --M. Haertel j.
17. Re: bytes_to_int
- Posted by your average Joe <spent_memory at hotmail.com> Feb 12, 2006
- 491 views
i ran the data where i was getting the clip problem through your algorithm and it appears to work very nicely Jay, stupid terragen information for developers webpage claims that they are 2 byte signed integers lol cheers, Joe
18. Re: bytes_to_int
- Posted by your average Joe <spent_memory at hotmail.com> Feb 12, 2006
- 489 views
Problem solved, i just ran it through my new modified pre converter and into opengl for rendering and was pleasantly surprised that is maps PERFECTLY now :). That was my problem that it needed to be a signed value. Oh the relief, ive been beating my head on the wall for 3 days on that one hehe. Thanx again Jay