R
Richard Heathfield
Zara said:
Apart from the other comments, there is no function called 'unsigned' in C.
Apart from the other comments, there is no function called 'unsigned' in C.
Of course, should this question really come up in a job interview, the
correct answer would be along the lines of "I'm sorry, but I don't want
to work here any more. I'd rather mow lawns than write that kind of
code. Goodbye, Mr. Ballmer."
My current computer is a DS9001 ultra turbo, with the compiler ecc (evil c
compiler) version 11.7.8.5.1.3.
sizeof (char) = 1
CHAR_BITS = 11
The rightmost bit is a signbit, and the other 10 bits forms the value.
"Negative Zero" is the trap value of course.
1 is encoded as 00000 00001 0
-1 as 00000 00001 1
and so on...
(could the above conform to the standard?)
/Niklas Norrthon
Ben said:I don't think that anyone else has yet pointed out that == and !=
are not relational operators, so there it is. (They are equality
operators.)
Jordan Abel said:Of course, should this question really come up in a job interview, the
correct answer would be along the lines of "I'm sorry, but I don't want
to work here any more. I'd rather mow lawns than write that kind of
code. Goodbye, Mr. Ballmer."
But then he would F*ing Kill You [tm], He Has Done It Before And He
Will Do It Again - all kidding aside, it's an interview question,
not a serious proposed program design.
Jordan said:No. -1 would have to be represented as any of the three:
10000000001 signed-magnitude
11111111110 ones complement
11111111111 twos complement
In C89, sign-(magnitude - 1) also is possible as any true binary
representation is allowed, so
10000000000
is in the game as well, as may be others.
C99 indeed restricts it to the three above.
Jordan Abel said:Of course, should this question really come up in a job interview, the
correct answer would be along the lines of "I'm sorry, but I don't want
to work here any more. I'd rather mow lawns than write that kind of
code. Goodbye, Mr. Ballmer."
But then he would F*ing Kill You [tm], He Has Done It Before And He
Will Do It Again - all kidding aside, it's an interview question,
not a serious proposed program design.
Yes, and all kidding aside, if a prospective employer thinks that this
is a question worth asking in a job interview I would think twice about
accepting a job there, because I would apparently have to work under a
management that does not understand what programming is about.
On 2005-10-26, Niklas Norrthon <[email protected]> wrote:
No. -1 would have to be represented as any of the three:
10000000001 signed-magnitude
11111111110 ones complement
11111111111 twos complement
In general, the sign bit has to be at the 'left' (i.e MSB for unsigned)
Yes and no. All value (magnitude) bits of the signed representation
must must have the same weights in unsigned so that all positive
signed numbers have the same representation as unsigned. The bit that
is the sign in signed may go unused (padding) in unsigned. If it is
used it must be _more_ significant than the 'common' value bits; it
still need not be _most_ significant if there are padding bits unused
in signed but used for value in unsigned, but that seems perverse.
- David.Thompson1 at worldnet.att.net
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.