Converting negative integer to octal/hexadecimal

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Sosman

    #16
    Re: Converting negative integer to octal/hexadecimal

    jaks.maths@gmai l.com wrote:[color=blue]
    > My question is to get cleared about the following.
    >
    > Can we have negative octal numbers and hex decimal numbers, Please
    > confirm?
    >
    > Vladimir Oka wrote:
    >[color=green]
    >>Eric Sosman wrote:
    >>[color=darkred]
    >>>jaks.maths@g mail.com wrote On 06/06/06 08:59,:
    >>>
    >>>>How to convert negative integer to hexadecimal or octal number?
    >>>>
    >>>>Ex: -568
    >>>>
    >>>>What is the equivalent hexadecimal and octal number??
    >>>
    >>> Hexadecimal: -0x238
    >>> Octal: -01070
    >>>
    >>> (These are not flippant answers. Pay no attention to
    >>>offered "answers" like 0xFFFFFDC8 or 037777776710, because
    >>>they merely perpetuate the confusion between representation
    >>>and value.)[/color]
    >>
    >>I guess the obviousness of the above correct answer leads to reading
    >>into the question something that (possibly) wasn't there in the first
    >>place. (Have the standards of teaching Maths declined that much?) To me
    >>at least, the intent of the original question is not 100% clear.[/color][/color]

    In C source, all integer constants expressed in decimal,
    octal, or hexadecimal are non-negative. There is no way to
    write a negative number in any of these bases.

    You can, however, combine constants with operators to
    form expressions with negative values. One easy way of doing
    this is to use the `-' operator as a prefix, as in `-42' or
    `-052' or `-0x2A'. These are not negative integer constants,
    but expressions each consisting of a positive integer constant
    and a `-' operator that negates its value.

    --
    Eric Sosman
    esosman@acm-dot-org.invalid

    Comment

    Working...