Re: Hexadecimal numbers in Eu
- Posted by "Juergen Luethje" <j.lue at gmx.de> Sep 19, 2004
- 419 views
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