1. Breaking down a large hex number.
- Posted by RedWordSmith <redwordsmith at NIC.DREAMHOST.COM> Jul 13, 2000
- 443 views
In a program I'm working on, I have a large number expressed in hexadecimal, in the format of blue = #1111222233333344444455677777789ABBBBBBCDEFF11 --Euphoria informs me this is about 1e+053 Where each "group" of numbers defines a trait (ie. "2222" is measurement for foo, while "A" is a measurement of bar) I'm trying to turn this mammoth into something more friendly to work with, along the lines of {#1111,#2222,#333333....} Now, just to make things more complicated, some of the numbers are themselves "groups" of the sort used in HTML color codes, for instance, "#333333" needs to become {51,51,51} so that the entire sequence ends up looking like: {#1111,#2222,{#33,#33,#33}...} The way I see to do this is using sprintf to turn the number into a string, break it apart based on position, then turns the strings back into correct numerical form within the final format. This seems like a rather round about way of doing things, but I've done something similiar in the past so I know it works. Does anyone know of another way of doing this? I know Mozilla can't be going through this sort of nonsense every time it needs to figure out what color a HTML document is. -- Nic (RedWord)Smith Alt.config Guide: http://nic.dreamhost.com/alt.config
2. Re: Breaking down a large hex number.
- Posted by Robert Craig <rds at ATTCANADA.NET> Jul 13, 2000
- 428 views
- Last edited Jul 14, 2000
RedWordSmith writes: > blue = #1111222233333344444455677777789ABBBBBBCDEFF11 > --Euphoria informs me this is about 1e+053 Be careful. atoms are only accurate to about 15 or 16 decimal digits, and something fewer in hex digits. Numbers as big as the one above, can't be stored reliably as atoms, without losing a lot of low-order hex digits. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
3. Re: Breaking down a large hex number.
- Posted by RedWordSmith <redwordsmith at NIC.DREAMHOST.COM> Jul 13, 2000
- 419 views
- Last edited Jul 14, 2000
Robert Craig wrote: > > RedWordSmith writes: > > blue = #1111222233333344444455677777789ABBBBBBCDEFF11 > > --Euphoria informs me this is about 1e+053 > > Be careful. atoms are only accurate to about > 15 or 16 decimal digits, and something fewer in hex digits. Ouch. I forgot about that. Thanks. I suppose the solution I had in mind won't work at all (oops). Not a big problem, I'll just have to store things proper instead of the admittedly bizarre (but much more easily modifiable) format I had in mind, and load information into the final sequence as it is read. -- Nic (RedWord)Smith Alt.config Guide: http://nic.dreamhost.com/alt.config
4. Re: Breaking down a large hex number.
- Posted by Kat <gertie at PELL.NET> Jul 13, 2000
- 446 views
- Last edited Jul 14, 2000
On 13 Jul 2000, at 22:40, Robert Craig wrote: > RedWordSmith writes: > > blue = #1111222233333344444455677777789ABBBBBBCDEFF11 > > --Euphoria informs me this is about 1e+053 > > Be careful. atoms are only accurate to about > 15 or 16 decimal digits, and something fewer in hex digits. > Numbers as big as the one above, can't be > stored reliably as atoms, without losing a lot of > low-order hex digits. Can you say string math? Kat
5. Re: Breaking down a large hex number.
- Posted by "Carl R. White" <cyrek at BIGFOOT.COM> Jul 14, 2000
- 435 views
On Thu, 13 Jul 2000 17:26:15 -0500, RedWordSmith <redwordsmith at NIC.DREAMHOST.COM> wrote: Hi. :) >I have a large number expressed in hexadecimal in the format of: > >blue = #1111222233333344444455677777789ABBBBBBCDEFF11 >--Euphoria informs me this is about 1e+053 If this is actual code from your program, it only runs if you define 'blue' to be an atom. Even then you'll only have 12-13 hex digits of accuracy, so everything after the 3's in your example would be garbled even if sprintf("%x",blue) actually worked with numbers this big! I get the feeling you've already figured most of this out though... The rest of your message indicates that you're getting the number from some outside source (Netscape? Web Page?) How exactly are you reading it into your program? Inputting from a text file, 'gets()' will get a string to begin with, so you wouldn't need sprintf(), and if you're typing the number in by hand, you may as well add the brackets by hand or type it in as a string... HTH, Carl -- no .sig