J
jaks.maths
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
Ex: -568
What is the equivalent hexadecimal and octal number??
[email protected] said:How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
From where I sit, the following program:
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
Eric said: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.)
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.
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
bert said:+568 = hex ...0000238 = 2 * 16^2 + 3 * 16 + 8
-568 = hex ...FFFFDC8, verify the sum is zero.
+568 = oct ...0001070 = 8^3 + 7 * 8
-568 = oct ...7776710, verify the sum is zero.
Vladimir said:From where I sit, the following program:
#include <stdio.h>
int main( void )
{
int i = -568;
printf("i = %x\n", i);
return 0;
}
produces the following:
i = fffffdc8
[FYI: that's 32 bit 2's complement. YMMV.]
Old said:Vladimir said:From where I sit, the following program:
#include <stdio.h>
int main( void )
{
int i = -568;
printf("i = %x\n", i);
return 0;
}
produces the following:
i = fffffdc8
[FYI: that's 32 bit 2's complement. YMMV.]
YMMV indeed because the program causes undefined behaviour:
the parameter corresponding to %x must be an unsigned int
(or, arguably, an int with a non-negative value).
You could replace the line with
printf( "i = %x\n", (unsigned)i );
and then it is clear that i is not fffffdc8; it is a different
number that i has been converted to.
My question is to get cleared about the following.
Can we have negative octal numbers and hex decimal numbers, Please
confirm?
[email protected] said:My question is to get cleared about the following.
Can we have negative octal numbers and hex decimal numbers, Please
confirm?
My question is to get cleared about the following.
Can we have negative octal numbers and hex decimal numbers, Please
confirm?
My question is to get cleared about the following.
Can we have negative octal numbers and hex decimal numbers, Please
confirm?
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.