1. Hexadecimal numbers in Eu
- Posted by "Juergen Luethje" <j.lue at gmx.de> Sep 16, 2004
- 441 views
Hi, in some other programming languages, hex numbers can represent positive or negative values. E.g. in PowerBASIC 3.2, ? &hFFF0 ' prints -16 ? &h00F0 ' prints 240 >From what I read at 'refman_2.htm#1' (Eu 2.4), and from my experience, I have the impression that hexadecimal numbers (that don't have a '-' sign at the beginning) in Euphoria _always_ have positive values. Rob, is this true? In Euphoria, e.g.
? #FFF0 -- prints 65520 ? #00F0 -- prints 240
Regards, Juergen -- /"\ ASCII ribbon campain | Superstition brings bad luck. \ / against HTML in | X e-mail and news, | / \ and unneeded MIME | http://home.arcor.de/luethje/prog/
2. Re: Hexadecimal numbers in Eu
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 16, 2004
- 441 views
Juergen Luethje wrote: > > Hi, > > in some other programming languages, hex numbers can represent positive > or negative values. E.g. in PowerBASIC 3.2, > ? &hFFF0 ' prints -16 > ? &h00F0 ' prints 240 > > >From what I read at 'refman_2.htm#1' (Eu 2.4), and from my experience, > I have the impression that hexadecimal numbers (that don't have a '-' > sign at the beginning) in Euphoria _always_ have positive values. > > Rob, is this true? > > In Euphoria, e.g. > }}} <eucode> > ? #FFF0 -- prints 65520 > ? #00F0 -- prints 240 > </eucode> {{{ Yes, hexadecimal literals are always positive unless they have a leading minus symbol. However it is a bit confusing because negative integers, when converted to display as hex digits via the printf() routine, display without the minus sign. printf(1, "%x", -1) --> FFFFFFFF -- Derek Parnell Melbourne, Australia
3. Re: Hexadecimal numbers in Eu
- Posted by "Juergen Luethje" <j.lue at gmx.de> Sep 16, 2004
- 459 views
Derek Parnell wrote: > Juergen Luethje wrote: >> >> Hi, >> >> in some other programming languages, hex numbers can represent positive >> or negative values. E.g. in PowerBASIC 3.2, >> ? &hFFF0 ' prints -16 >> ? &h00F0 ' prints 240 >> >>> From what I read at 'refman_2.htm#1' (Eu 2.4), and from my experience, >> I have the impression that hexadecimal numbers (that don't have a '-' >> sign at the beginning) in Euphoria _always_ have positive values. >> >> Rob, is this true? >> >> In Euphoria, e.g. >> }}} <eucode> >> ? #FFF0 -- prints 65520 >> ? #00F0 -- prints 240 >> </eucode> {{{ > > > Yes, hexadecimal literals are always positive unless they have a leading > minus symbol. Rob, maybe this sentence could be added to the docs? I think it will be very helpful for beginners -- and people like me, who sometimes feel like beginners. [[Grrmmpf.. "leading". That is the word I was searching for, in any corner of my brain, and didn't find it. ]] > However it is a bit confusing because negative integers, when converted > to display as hex digits via the printf() routine, display without > the minus sign. > > printf(1, "%x", -1) --> FFFFFFFF Yes, this actually confused me some days ago!! Thanks, Derek! Rob, is there any chance that in a future version of Euphoria, printf(1, "%x", -1) will show '-1' or '-#1' instead of 'FFFFFFFF'? Regards, Juergen -- A: Because it considerably reduces the readability of the text. Q: Why? A: Top posting. Q: What is annoying in e-mail and news?
4. Re: Hexadecimal numbers in Eu
- Posted by D L <d1eu at yahoo.ca> Sep 18, 2004
- 426 views
It is just a matter of interpretation. Do you use 00000000-FFFFFFFF as an all positive range, or split it halfway to have positive and negative values?. The halfway is the tricky part, because it does not follow the "normal" decimal sequence, i.e. start at the most negative, thru zero and on to the most positive. You start at 0 dec/hex, go up to the largest positive (7F FF FF FF) and then continue counting from the most negative (80 00 00 00) up to -1 dec/FF FF FF FF hex. To get negative decimal values test hex, if it is #80 00 00 00 or larger then use formula: negative decimal=-(not_bits(hex)+1) All assuming hex is represented using 4 bytes (note: print %x seems to set the limit at 4 bytes). Denes L.
5. Re: Hexadecimal numbers in Eu
- Posted by "Juergen Luethje" <j.lue at gmx.de> Sep 18, 2004
- 431 views
D L wrote: > It is just a matter of interpretation. > Do you use 00000000-FFFFFFFF as an all positive range, or split it halfway to > have positive and negative values?. > > The halfway is the tricky part, because it does not follow the "normal" > decimal sequence, i.e. start at the most negative, thru zero and on to the most > positive. > > You start at 0 dec/hex, go up to the largest positive (7F FF FF FF) and then > continue counting from the most negative (80 00 00 00) up to -1 dec/FF FF FF FF > hex. > > To get negative decimal values test hex, if it is #80 00 00 00 or larger then > use formula: > negative decimal=-(not_bits(hex)+1) > > All assuming hex is represented using 4 bytes (note: print %x seems to set the > limit at 4 bytes). I wrote something similar one week or so ago in a different thread ... What question are you trying to answer here? I can't even see to which post you are replying, neither formally nor regarding the content. When you reply to a post, please quote the text that you are referring to. For details e.g. see here: http://www.netmeister.org/news/learn2quote.html My first question in this thread has already been answered by Derek. Then I asked Rob two additional questions. He didn't reply until now, however, I don't think that anyone else can answer the questions. Regards, Juergen -- /"\ ASCII ribbon campain | Math problems? \ / against HTML in | Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]. X e-mail and news, | / \ and unneeded MIME | http://home.arcor.de/luethje/prog/
6. Re: Hexadecimal numbers in Eu
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 18, 2004
- 430 views
Juergen Luethje wrote: > > Derek Parnell wrote: > > > Juergen Luethje wrote: > >> > >> Hi, > >> > >> in some other programming languages, hex numbers can represent positive > >> or negative values. E.g. in PowerBASIC 3.2, > >> ? &hFFF0 ' prints -16 > >> ? &h00F0 ' prints 240 > >> > >>> From what I read at 'refman_2.htm#1' (Eu 2.4), and from my experience, > >> I have the impression that hexadecimal numbers (that don't have a '-' > >> sign at the beginning) in Euphoria _always_ have positive values. > >> > >> Rob, is this true? > >> > >> In Euphoria, e.g. > >> }}} <eucode> > >> ? #FFF0 -- prints 65520 > >> ? #00F0 -- prints 240 > >> </eucode> {{{ > > > > > > Yes, hexadecimal literals are always positive unless they have a leading > > minus symbol. > > Rob, maybe this sentence could be added to the docs? I think it will be > very helpful for beginners -- and people like me, who sometimes feel > like beginners. OK, I'll say something in the docs about this. > > However it is a bit confusing because negative integers, when converted > > to display as hex digits via the printf() routine, display without > > the minus sign. > > > > printf(1, "%x", -1) --> FFFFFFFF > > Yes, this actually confused me some days ago!! Thanks, Derek! > > Rob, is there any chance that in a future version of Euphoria, > printf(1, "%x", -1) > will show '-1' or '-#1' instead of 'FFFFFFFF'? Euphoria's %x format for printf() uses C's %x format, and only works for numbers up to 32-bits in size.
printf(1, "%x", #FFFFFFFF)
displays FFFFFFFF as does:
printf(1, "%x", -1)
but Euphoria does *not* consider #FFFFFFFF to be equal to -1. When people are printing numbers with %x format they usually want to see -1 displayed as FFFFFFFF, so I don't plan to change it. Just as people have made their own versions of pretty_print(), there's no reason someone couldn't make an enhanced version of printf(), with lots of fancy new % formats. Very few programs require a really fast printf(). Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
7. Re: Hexadecimal numbers in Eu
- Posted by "Juergen Luethje" <j.lue at gmx.de> Sep 19, 2004
- 470 views
Robert Craig wrote: > Juergen Luethje wrote: >> >> Derek Parnell wrote: >> >>> Juergen Luethje wrote: >>>> >>>> Hi, >>>> >>>> in some other programming languages, hex numbers can represent positive >>>> or negative values. E.g. in PowerBASIC 3.2, >>>> ? &hFFF0 ' prints -16 >>>> ? &h00F0 ' prints 240 >>>> >>>>> From what I read at 'refman_2.htm#1' (Eu 2.4), and from my experience, >>>> I have the impression that hexadecimal numbers (that don't have a '-' >>>> sign at the beginning) in Euphoria _always_ have positive values. >>>> >>>> Rob, is this true? >>>> >>>> In Euphoria, e.g. >>>> }}} <eucode> >>>> ? #FFF0 -- prints 65520 >>>> ? #00F0 -- prints 240 >>>> </eucode> {{{ >>> >>> >>> Yes, hexadecimal literals are always positive unless they have a leading >>> minus symbol. >> >> Rob, maybe this sentence could be added to the docs? I think it will be >> very helpful for beginners -- and people like me, who sometimes feel >> like beginners. > > OK, I'll say something in the docs about this. Thanks, that will eliminate ambiguity. >>> However it is a bit confusing because negative integers, when converted >>> to display as hex digits via the printf() routine, display without >>> the minus sign. >>> >>> printf(1, "%x", -1) --> FFFFFFFF >> >> Yes, this actually confused me some days ago!! Thanks, Derek! >> >> Rob, is there any chance that in a future version of Euphoria, >> printf(1, "%x", -1) >> will show '-1' or '-#1' instead of 'FFFFFFFF'? > > Euphoria's %x format for printf() uses C's %x format, > and only works for numbers up to 32-bits in size. > }}} <eucode> > printf(1, "%x", #FFFFFFFF) > </eucode> {{{ > displays FFFFFFFF > as does: > }}} <eucode> > printf(1, "%x", -1) > </eucode> {{{ > but Euphoria does *not* consider #FFFFFFFF to be equal to -1. Either it should do so, or
printf(1, "%x", -1)
should *not* display FFFFFFFF!! This is a great inconsistency, and a source for confusion (as Derek wrote, too) and bugs. > When people are printing numbers with %x format > they usually want to see -1 displayed as FFFFFFFF, It depends. E.g. people who are new to programming probably would not expect anything, because it will be the first time they deal with hex numbers, and they just learn what they see. I agree that more experienced programmers, printing numbers with %x format, probably want to see -1 displayed as FFFFFFFF. But this people probably also want Euphoria to consider #FFFFFFFF to be equal to -1! So most important IMHO: Neither newbies nor 'oldbies' do like inconsistencies! Especially not in a programming language, which is for them a tool that should help them to perform *logical* operations.
include get.e type int_32bit (object x) -- 32-bit integer (signed or unsigned) if atom(x) then if x = floor(x) and -#80000000 <= x and x <= #FFFFFFFF then return 1 end if end if return 0 end type function xconvert (int_32bit a) sequence ret ret = value(sprintf("#%x", a)) if ret[1] != GET_SUCCESS then puts(1, "Error concerning value(), program terminated!") abort(1) end if return ret[2] end function int_32bit a, v a = -1 puts(1, "Handling of hexadecimal numbers (Eu 2.4):\n") v = xconvert(a) if v = a then printf(1, "%d = %d\n", {v, a}) puts(1, "consistent behaviour ") else printf(1, "%d != %d\n", {v, a}) puts(1, "inconsistent behaviour ") end if
For any negative value of 'a', this test will show inconsistent behaviour. Except of backward compatibility, I can't see any reason why this behaviour should be maintained. > so I don't plan to change it. > Just as people have made their own versions of pretty_print(), > there's no reason someone couldn't make an enhanced version > of printf(), with lots of fancy new % formats. Very few programs > require a really fast printf(). I know, but that was not my point. Newbies are probably not able to make their own version of printf(). Also, I (and other people, too) want their Eu code to be compatible with the rest of the Eu world. What I wrote was neither a request for a feature that I just want privately, nor a wish for a "fancy new % format", but a serious suggestion for improvement of Euphoria in general. If you don't want to implement it, I'll accept it. But please recognize the difference. Regards, Juergen -- /"\ ASCII ribbon campain | This message has been ROT-13 encrypted \ / against HTML in | twice for higher security. X e-mail and news, | / \ and unneeded MIME | http://home.arcor.de/luethje/prog/
8. Re: Hexadecimal numbers in Eu
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 19, 2004
- 425 views
Juergen Luethje wrote: > > Robert Craig wrote: > > > Juergen Luethje wrote: > >> > >> Derek Parnell wrote: > >> > >>> Juergen Luethje wrote: > >>>> > >>>> Hi, > >>>> > >>>> in some other programming languages, hex numbers can represent positive > >>>> or negative values. E.g. in PowerBASIC 3.2, > >>>> ? &hFFF0 ' prints -16 > >>>> ? &h00F0 ' prints 240 > >>>> > >>>>> From what I read at 'refman_2.htm#1' (Eu 2.4), and from my experience, > >>>> I have the impression that hexadecimal numbers (that don't have a '-' > >>>> sign at the beginning) in Euphoria _always_ have positive values. > >>>> > >>>> Rob, is this true? > >>>> > >>>> In Euphoria, e.g. > >>>> }}} <eucode> > >>>> ? #FFF0 -- prints 65520 > >>>> ? #00F0 -- prints 240 > >>>> </eucode> {{{ > >>> > >>> > >>> Yes, hexadecimal literals are always positive unless they have a leading > >>> minus symbol. > >> > >> Rob, maybe this sentence could be added to the docs? I think it will be > >> very helpful for beginners -- and people like me, who sometimes feel > >> like beginners. > > > > OK, I'll say something in the docs about this. > > Thanks, that will eliminate ambiguity. > > >>> However it is a bit confusing because negative integers, when converted > >>> to display as hex digits via the printf() routine, display without > >>> the minus sign. > >>> > >>> printf(1, "%x", -1) --> FFFFFFFF > >> > >> Yes, this actually confused me some days ago!! Thanks, Derek! > >> > >> Rob, is there any chance that in a future version of Euphoria, > >> printf(1, "%x", -1) > >> will show '-1' or '-#1' instead of 'FFFFFFFF'? > > > > Euphoria's %x format for printf() uses C's %x format, > > and only works for numbers up to 32-bits in size. > > }}} <eucode> > > printf(1, "%x", #FFFFFFFF) > > </eucode> {{{ > > displays FFFFFFFF > > as does: > > }}} <eucode> > > printf(1, "%x", -1) > > </eucode> {{{ > > but Euphoria does *not* consider #FFFFFFFF to be equal to -1. > > Either it should do so, or > }}} <eucode> > printf(1, "%x", -1) > </eucode> {{{ > should *not* display FFFFFFFF!! > This is a great inconsistency, and a source for confusion (as Derek > wrote, too) and bugs. > > > When people are printing numbers with %x format > > they usually want to see -1 displayed as FFFFFFFF, > > It depends. E.g. people who are new to programming probably would not > expect anything, because it will be the first time they deal with hex > numbers, and they just learn what they see. I'll interject just here because we probably should understand the purpose of %x. My understanding is it is used to display the bit pattern of the integer, as it is represented in RAM. And thus -1 should be output as FFFFFFFF because that is how -1 is represented as a 32-bit value. I agree it is confusing if you don't know that's what %x is trying to do. > I agree that more experienced programmers, printing numbers with %x > format, probably want to see -1 displayed as FFFFFFFF. But this people > probably also want Euphoria to consider #FFFFFFFF to be equal to -1! The difference between #FFFFFFFF and the output of %x is that the first is a literal coded into the source code, and such literals are always positive integers. And the second is bit pattern display of the integer in RAM. If you want to use negative hexadecimal literals you just place a '-' in front of the literal. atom test test = -#1 test = -#FFFF If you want to display the value (rather than the bit pattern) of an integer in hexadecimal format try this ... if test < 0 then printf(1, "-%x, ", -test) else printf(1, "%x, ", test) end if -- Derek Parnell Melbourne, Australia
9. Re: Hexadecimal numbers in Eu
- Posted by "Juergen Luethje" <j.lue at gmx.de> Sep 19, 2004
- 414 views
- Last edited Sep 20, 2004
Derek Parnell wrote: > Juergen Luethje wrote: >> >> Robert Craig wrote: <big snip> >>> When people are printing numbers with %x format >>> they usually want to see -1 displayed as FFFFFFFF, >> >> It depends. E.g. people who are new to programming probably would not >> expect anything, because it will be the first time they deal with hex >> numbers, and they just learn what they see. > > > I'll interject just here because we probably should understand the > purpose of %x. My understanding is it is used to display the bit pattern > of the integer, as it is represented in RAM. And thus -1 should be > output as FFFFFFFF because that is how -1 is represented as a 32-bit > value. Aaaah! > I agree it is confusing if you don't know that's what %x is trying to > do. > >> I agree that more experienced programmers, printing numbers with %x >> format, probably want to see -1 displayed as FFFFFFFF. But this people >> probably also want Euphoria to consider #FFFFFFFF to be equal to -1! > > The difference between #FFFFFFFF and the output of %x is that the first > is a literal coded into the source code, and such literals are always > positive integers. And the second is bit pattern display of the integer > in RAM. > > If you want to use negative hexadecimal literals you just place a '-' > in front of the literal. > > atom test > test = -#1 > test = -#FFFF > > If you want to display the value (rather than the bit pattern) of an > integer in hexadecimal format try this ... > > if test < 0 then > printf(1, "-%x, ", -test) > else > printf(1, "%x, ", test) > end if I think, I understand now. Thanks a lot for the comprehensive explanation, Derek! Regards, Juergen
10. Re: Hexadecimal numbers in Eu
- Posted by D L <d1eu at yahoo.ca> Sep 19, 2004
- 435 views
- Last edited Sep 20, 2004
Juergen Luethje wrote: > What question are you trying to answer here? > I can't even see to which post you are replying, neither formally nor > regarding the content. When you reply to a post, please quote the text > that you are referring to... I was sharing information (hint: forum) that could be useful to somebody reading the posts on the Subject: Hexadecimal numbers in Eu. If the info is not useful to you it might be to somebody else. No need to quote since it was a general observation. Juergen Luethje wrote: > I wrote something similar one week or so ago in a different thread ... I have not read the whole forum and I don't intend to. By the way you missed one of my posts where I was quoting someone. Juergen Luethje wrote: > I don't think that anyone else can answer the questions. > Aaaah! > I think, I understand now. Thanks a lot for the comprehensive > explanation, Derek! Good!. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - refman2 says: Atoms can have any integer or double-precision floating point value. They can range from approximately -1e300 (minus one times 10 to the power 300) to +1e300 with 15 decimal digits of accuracy... Numbers can also be entered in hexadecimal... Maybe Rob can give more details on how numbers are stored. Regards, Denes L.
11. Re: Hexadecimal numbers in Eu
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 19, 2004
- 440 views
- Last edited Sep 20, 2004
D L wrote: [snip] > refman2 says: Atoms can have any integer or double-precision floating point > value. They can range from approximately -1e300 (minus one times 10 to the > power 300) to +1e300 with 15 decimal digits of accuracy... > Numbers can also be entered in hexadecimal... > > Maybe Rob can give more details on how numbers are stored. >From memory, integers are stored as 30-bit values plus a 1-bit sign flag. Atom are IEEE 64-bit floating point values. -- Derek Parnell Melbourne, Australia
12. Re: Hexadecimal numbers in Eu
- Posted by "Juergen Luethje" <j.lue at gmx.de> Sep 20, 2004
- 431 views
D L wrote: > Juergen Luethje wrote: >> What question are you trying to answer here? >> I can't even see to which post you are replying, neither formally nor >> regarding the content. When you reply to a post, please quote the text >> that you are referring to... > > I was sharing information (hint: forum) that could be useful to somebody > reading the posts on the Subject: Hexadecimal numbers in Eu. > If the info is not useful to you it might be to somebody else. No need to > quote since it was a general observation. Just sending some "general observations" to the world is not the way, how discussions work. <snip> Regards, Juergen
13. Re: Hexadecimal numbers in Eu
- Posted by "Unkmar" <L3Euphoria at bellsouth.net> Sep 20, 2004
- 441 views
----- Original Message ----- From: "Derek Parnell" <guest at RapidEuphoria.com> To: <EUforum at topica.com> Sent: Sunday, September 19, 2004 10:42 AM Subject: Re: Hexadecimal numbers in Eu > > > posted by: Derek Parnell <ddparnell at bigpond.com> > > Juergen Luethje wrote: > > > > Robert Craig wrote: > > > > > Juergen Luethje wrote: > > >> > > >> Derek Parnell wrote: > > >> > > >>> Juergen Luethje wrote: > > >>>> > > >>>> Hi, > > >>>> > > >>>> in some other programming languages, hex numbers can represent positive > > >>>> or negative values. E.g. in PowerBASIC 3.2, > > >>>> ? &hFFF0 ' prints -16 > > >>>> ? &h00F0 ' prints 240 > > >>>> > > >>>>> From what I read at 'refman_2.htm#1' (Eu 2.4), and from my experience, > > >>>> I have the impression that hexadecimal numbers (that don't have a '-' > > >>>> sign at the beginning) in Euphoria _always_ have positive values. > > >>>> > > >>>> Rob, is this true? > > >>>> > > >>>> In Euphoria, e.g. > > >>>> }}} <eucode> > > >>>> ? #FFF0 -- prints 65520 > > >>>> ? #00F0 -- prints 240 > > >>>> </eucode> {{{ > > >>> > > >>> > > >>> Yes, hexadecimal literals are always positive unless they have a leading > > >>> minus symbol. > > >> > > >> Rob, maybe this sentence could be added to the docs? I think it will be > > >> very helpful for beginners -- and people like me, who sometimes feel > > >> like beginners. > > > > > > OK, I'll say something in the docs about this. > > > > Thanks, that will eliminate ambiguity. > > > > >>> However it is a bit confusing because negative integers, when converted > > >>> to display as hex digits via the printf() routine, display without > > >>> the minus sign. > > >>> > > >>> printf(1, "%x", -1) --> FFFFFFFF > > >> > > >> Yes, this actually confused me some days ago!! Thanks, Derek! > > >> > > >> Rob, is there any chance that in a future version of Euphoria, > > >> printf(1, "%x", -1) > > >> will show '-1' or '-#1' instead of 'FFFFFFFF'? > > > > > > Euphoria's %x format for printf() uses C's %x format, > > > and only works for numbers up to 32-bits in size. > > > }}} <eucode> > > > printf(1, "%x", #FFFFFFFF) > > > </eucode> {{{ > > > displays FFFFFFFF > > > as does: > > > }}} <eucode> > > > printf(1, "%x", -1) > > > </eucode> {{{ > > > but Euphoria does *not* consider #FFFFFFFF to be equal to -1. > > > > Either it should do so, or > > }}} <eucode> > > printf(1, "%x", -1) > > </eucode> {{{ > > should *not* display FFFFFFFF!! > > This is a great inconsistency, and a source for confusion (as Derek > > wrote, too) and bugs. > > > > > When people are printing numbers with %x format > > > they usually want to see -1 displayed as FFFFFFFF, > > > > It depends. E.g. people who are new to programming probably would not > > expect anything, because it will be the first time they deal with hex > > numbers, and they just learn what they see. > > > I'll interject just here because we probably should understand the > purpose of %x. My understanding is it is used to display the bit pattern > of the integer, as it is represented in RAM. And thus -1 should be > output as FFFFFFFF because that is how -1 is represented as a 32-bit > value. > > I agree it is confusing if you don't know that's what %x is trying to > do. > > > I agree that more experienced programmers, printing numbers with %x > > format, probably want to see -1 displayed as FFFFFFFF. But this people > > probably also want Euphoria to consider #FFFFFFFF to be equal to -1! > > The difference between #FFFFFFFF and the output of %x is that the first > is a literal coded into the source code, and such literals are always > positive integers. And the second is bit pattern display of the integer > in RAM. > > If you want to use negative hexadecimal literals you just place a '-' > in front of the literal. > > atom test > test = -#1 > test = -#FFFF > > If you want to display the value (rather than the bit pattern) of an > integer in hexadecimal format try this ... > > if test < 0 then > printf(1, "-%x, ", -test) > else > printf(1, "%x, ", test) > end if > > -- > Derek Parnell > Melbourne, Australia Yeah, what Derek said. unkmar
14. Re: Hexadecimal numbers in Eu
- Posted by cklester <cklester at yahoo.com> Sep 20, 2004
- 440 views
Unkmar wrote: > > ----- Original Message ----- > From: "Derek Parnell" <guest at RapidEuphoria.com> > To: <EUforum at topica.com> > Sent: Sunday, September 19, 2004 10:42 AM > Subject: Re: Hexadecimal numbers in Eu > > > > posted by: Derek Parnell <ddparnell at bigpond.com> > > > > Juergen Luethje wrote: > > > > > > Robert Craig wrote: > > > > > > > Juergen Luethje wrote: > > > >> > > > >> Derek Parnell wrote: > > > >> > > > >>> Juergen Luethje wrote: > > > >>>> > > > >>>> Hi, > > > >>>> > > > >>>> in some other programming languages, hex numbers can represent > positive > > > >>>> or negative values. E.g. in PowerBASIC 3.2, > > > >>>> ? &hFFF0 ' prints -16 > > > >>>> ? &h00F0 ' prints 240 > > > >>>> > > > >>>>> From what I read at 'refman_2.htm#1' (Eu 2.4), and from my > experience, > > > >>>> I have the impression that hexadecimal numbers (that don't have a > '-' > > > >>>> sign at the beginning) in Euphoria _always_ have positive values. > > > >>>> > > > >>>> Rob, is this true? > > > >>>> > > > >>>> In Euphoria, e.g. > > > >>>> }}} <eucode> > > > >>>> ? #FFF0 -- prints 65520 > > > >>>> ? #00F0 -- prints 240 > > > >>>> </eucode> {{{ > > > >>> > > > >>> > > > >>> Yes, hexadecimal literals are always positive unless they have a > leading > > > >>> minus symbol. > > > >> > > > >> Rob, maybe this sentence could be added to the docs? I think it will > be > > > >> very helpful for beginners -- and people like me, who sometimes feel > > > >> like beginners. > > > > > > > > OK, I'll say something in the docs about this. > > > > > > Thanks, that will eliminate ambiguity. > > > > > > >>> However it is a bit confusing because negative integers, when > converted > > > >>> to display as hex digits via the printf() routine, display without > > > >>> the minus sign. > > > >>> > > > >>> printf(1, "%x", -1) --> FFFFFFFF > > > >> > > > >> Yes, this actually confused me some days ago!! Thanks, Derek! > > > >> > > > >> Rob, is there any chance that in a future version of Euphoria, > > > >> printf(1, "%x", -1) > > > >> will show '-1' or '-#1' instead of 'FFFFFFFF'? > > > > > > > > Euphoria's %x format for printf() uses C's %x format, > > > > and only works for numbers up to 32-bits in size. > > > > }}} <eucode> > > > > printf(1, "%x", #FFFFFFFF) > > > > </eucode> {{{ > > > > displays FFFFFFFF > > > > as does: > > > > }}} <eucode> > > > > printf(1, "%x", -1) > > > > </eucode> {{{ > > > > but Euphoria does *not* consider #FFFFFFFF to be equal to -1. > > > > > > Either it should do so, or > > > }}} <eucode> > > > printf(1, "%x", -1) > > > </eucode> {{{ > > > should *not* display FFFFFFFF!! > > > This is a great inconsistency, and a source for confusion (as Derek > > > wrote, too) and bugs. > > > > > > > When people are printing numbers with %x format > > > > they usually want to see -1 displayed as FFFFFFFF, > > > > > > It depends. E.g. people who are new to programming probably would not > > > expect anything, because it will be the first time they deal with hex > > > numbers, and they just learn what they see. > > > > > > I'll interject just here because we probably should understand the <snip> Did you HAVE to quote the entire post?! sheesh. -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
15. Re: Hexadecimal numbers in Eu
- Posted by "Kat" <gertie at visionsix.com> Sep 20, 2004
- 432 views
On 20 Sep 2004, at 9:04, cklester wrote: <snip> ?! sheesh. no Kat
16. Re: Hexadecimal numbers in Eu
- Posted by "Igor Kachan" <kinz at peterlink.ru> Sep 20, 2004
- 428 views
Hi > <snip> > > ?! sheesh. > > no Wow! What? -- Igor
17. Re: Hexadecimal numbers in Eu
- Posted by CoJaBo <cojabo at suscom.net> Sep 20, 2004
- 448 views
- Last edited Sep 21, 2004
cklester wrote: > > Unkmar wrote: > > > > ----- Original Message ----- > > From: "Derek Parnell" <guest at RapidEuphoria.com> > > To: <EUforum at topica.com> > > Sent: Sunday, September 19, 2004 10:42 AM > > Subject: Re: Hexadecimal numbers in Eu > > > > > > > posted by: Derek Parnell <ddparnell at bigpond.com> > > > > > > Juergen Luethje wrote: > > > > > > > > Robert Craig wrote: > > > > > > > > > Juergen Luethje wrote: > > > > >> > > > > >> Derek Parnell wrote: > > > > >> > > > > >>> Juergen Luethje wrote: > > > > >>>> > > > > >>>> Hi, > > > > >>>> > > > > >>>> in some other programming languages, hex numbers can represent > > positive > > > > >>>> or negative values. E.g. in PowerBASIC 3.2, > > > > >>>> ? &hFFF0 ' prints -16 > > > > >>>> ? &h00F0 ' prints 240 > > > > >>>> > > > > >>>>> From what I read at 'refman_2.htm#1' (Eu 2.4), and from my > > experience, > > > > >>>> I have the impression that hexadecimal numbers (that don't have a > > '-' > > > > >>>> sign at the beginning) in Euphoria _always_ have positive values. > > > > >>>> > > > > >>>> Rob, is this true? > > > > >>>> > > > > >>>> In Euphoria, e.g. > > > > >>>> }}} <eucode> > > > > >>>> ? #FFF0 -- prints 65520 > > > > >>>> ? #00F0 -- prints 240 > > > > >>>> </eucode> {{{ > > > > >>> > > > > >>> > > > > >>> Yes, hexadecimal literals are always positive unless they have a > > leading > > > > >>> minus symbol. > > > > >> > > > > >> Rob, maybe this sentence could be added to the docs? I think it will > > be > > > > >> very helpful for beginners -- and people like me, who sometimes feel > > > > >> like beginners. > > > > > > > > > > OK, I'll say something in the docs about this. > > > > > > > > Thanks, that will eliminate ambiguity. > > > > > > > > >>> However it is a bit confusing because negative integers, when > > converted > > > > >>> to display as hex digits via the printf() routine, display without > > > > >>> the minus sign. > > > > >>> > > > > >>> printf(1, "%x", -1) --> FFFFFFFF > > > > >> > > > > >> Yes, this actually confused me some days ago!! Thanks, Derek! > > > > >> > > > > >> Rob, is there any chance that in a future version of Euphoria, > > > > >> printf(1, "%x", -1) > > > > >> will show '-1' or '-#1' instead of 'FFFFFFFF'? > > > > > > > > > > Euphoria's %x format for printf() uses C's %x format, > > > > > and only works for numbers up to 32-bits in size. > > > > > }}} <eucode> > > > > > printf(1, "%x", #FFFFFFFF) > > > > > </eucode> {{{ > > > > > displays FFFFFFFF > > > > > as does: > > > > > }}} <eucode> > > > > > printf(1, "%x", -1) > > > > > </eucode> {{{ > > > > > but Euphoria does *not* consider #FFFFFFFF to be equal to -1. > > > > > > > > Either it should do so, or > > > > }}} <eucode> > > > > printf(1, "%x", -1) > > > > </eucode> {{{ > > > > should *not* display FFFFFFFF!! > > > > This is a great inconsistency, and a source for confusion (as Derek > > > > wrote, too) and bugs. > > > > > > > > > When people are printing numbers with %x format > > > > > they usually want to see -1 displayed as FFFFFFFF, > > > > > > > > It depends. E.g. people who are new to programming probably would not > > > > expect anything, because it will be the first time they deal with hex > > > > numbers, and they just learn what they see. > > > > > > > > > I'll interject just here because we probably should understand the <snip> > > -=ck > "Programming in a state of EUPHORIA." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> >