Re: Hexadecimal numbers in Eu

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

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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu