1. hex2seq() and seq2hex()
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Jul 15, 1999
- 352 views
Hello everyone, I'm writing a couple of routines for converting between a hex value and a sequence: eg: #RRGGBB --> {#RR,#GG,#BB} and {#RR,#GG,#BB} --> #RRGGBB If anyone has better ones or knows of better ones please post them. BTW, my second one (seq2hex()) doesn't seem to work right, I'd like to know why. Here they are: function hex2seq (atom hex) sequence seq seq = {0,0,0} seq[1] = floor (hex / #010000) seq[2] = floor (hex / #000100) -seq[1]*#100 seq[3] = floor (hex / #000001) -seq[1]*#10000 -seq[2]*#100 return seq end function function seq2hex (sequence seq) return seq[1]*#1000 + seq[2]*#100 + seq[3] end function later, Lewis Townsend _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com
2. Re: hex2seq() and seq2hex()
- Posted by Mike Sabal <MikeS at NOTATIONS.COM> Jul 15, 1999
- 340 views
>>> Lewis Townsend <keroltarr at HOTMAIL.COM> 07/15/99 12:37PM >>> my second one (seq2hex()) doesn't seem to work right, I'd like to know why. function seq2hex (sequence seq) return seq[1]*#1000 + seq[2]*#100 + seq[3] end function ------------------------------------- Perhaps that should be seq[1]*#10000. Michael J. Sabal
3. Re: hex2seq() and seq2hex()
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Jul 15, 1999
- 333 views
>Perhaps that should be seq[1]*#10000. > >Michael J. Sabal Thanks, now it gives me the right answer. How about optimizations now? Lewis Townsend _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com
4. Re: hex2seq() and seq2hex()
- Posted by Robert <rmanny at THEGRID.NET> Jul 15, 1999
- 345 views
I'm new to this language, but will this work? There's also a bytes_to_int that should do the reverse. Robert --*** include files *** include machine.e --*** declare vars *** sequence a atom i i = #FFC24A --*** main global procedure *** global procedure Main () a = int_to_bytes(i) printf(1,"%x ",a[3])printf(1,"%x ",a[2])printf(1,"%x",a[1]) end procedure Main() --------------------------------------------------------------------------------------- Lewis Townsend wrote: > Hello everyone, > > I'm writing a couple of routines for converting between a hex value and a > sequence: > eg: #RRGGBB --> {#RR,#GG,#BB} > and {#RR,#GG,#BB} --> #RRGGBB > If anyone has better ones or knows of better ones please post them. BTW, my > second one (seq2hex()) doesn't seem to work right, I'd like to know why. > Here they are: > > function hex2seq (atom hex) > sequence seq seq = {0,0,0} > seq[1] = floor (hex / #010000) > seq[2] = floor (hex / #000100) -seq[1]*#100 > seq[3] = floor (hex / #000001) -seq[1]*#10000 -seq[2]*#100 > return seq > end function > > function seq2hex (sequence seq) > return seq[1]*#1000 + seq[2]*#100 + seq[3] > end function > > later, > Lewis Townsend > > _______________________________________________________________ > Get Free Email and Do More On The Web. Visit http://www.msn.com