Re: Hexadecimal numbers in Eu

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

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. smile

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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu