ja********@gmail.com wrote:

My question is to get cleared about the following.

Can we have negative octal numbers and hex decimal numbers, Please

confirm?

There are no "octal numbers" or "hexadecimal numbers". There are

numbers /written in/ octal and hexadecimal, just as there are

numbers /written in/ decimal.

A lot of the time - such as in casual conversational use - the distinction

between decimal /numerals/ and the /numbers/ they represent doesn't

much matter; but programming isn't one of those times.

You can write some decimal numeral, eg 1066. This represents a positive

number. You can write some hexadecimal number, eg 0xffff. This also

represents some positive number. You /can't/ write a decimal numeral

that represents a negative number, and you /can't/ represent a

hexadecimal number that represents a negative number either.

What you /can/ write is a numeral that expresses a number which cannot

be expressed in the number of bits allocated for its representation

by its context. For example, when you write 12345678910111213141516,

its value typically cannot be represented as a C int; similarly

0xffffffff cannot be represented as a C int if the implementation

uses 32-bit ints.

Various things are permitted to happen, and I don't offhand know

the details, but one outcome that /may/ happen is that the bits of

the /binary/ numeral that represents the value are stuffed willy-nilly

into the representation, and a bit that was supposed to represent a

big and positive value occupies the slot used for a big and /negative/

value, so that this twos-complement binary numeral represents a

negative number.

So a numeral 0xffffffff may end up being a bit-pattern that represents

a negative number in your implementation. It's not the hexadecimal

number that's negative: it's the surviving bitsvalue after its been

pintpotted into the available space.

Just as on a 16-bit-int implementation, the numeral 40000 may end

up as a bitpattern the machine thinks represents a negative number.

This doesn't mean that (the value represented by the decimal number) 40000

is negative.

--

Chris "seeker" Dollin

"Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/