answersLogoWhite

0


Best Answer

With a signed integer, the top bit is used to hold the sign of the number, so that the range of numbers that can be held is -(2number_of_bits-1) to 2number_of_bits-1 -1, whereas with an unsigned integer, all the bits are used to store the number which will always be positive and so the range is 0 to 2number_of_bits -1.

For example, with 16 bits, a signed integer has the range -(215) to 215 -1 = -32768 to 32767 whereas an unsigned integer has the range 0 to 216 -1 = 0 to 65535.

The point in particular to note is how the numbers (bit patterns) with the top bit set are interpreted: with unsigned ints they are greater than those without the top bit set (eg 0xffff = 65535 > 0x7fff = 32767), but with signed ints they are less (eg 0xffff = -1 < 0x7fff = 32767).

I'm not sure about the significance of declaring a constant as unsigned (having never used one), but at a guess I would say it's to tell the compiler that the bit pattern is an unsigned bit pattern and to throw up a warning (or error) if it's used with a signed bit pattern, eg if used in a comparison with a signed int - ie an aid to cutting down on bugs by ensuring that things are only used for their intended purpose.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is an unsigned integerWhat is significance of declaring a constant unsigned?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the significance of declaring a constant unsigned integer?

What is the significance of declaring a constant unsigned integer?


What if a warranty deed is not signed and notarized?

An unsigned deed is just a piece of paper. It has no significance until it is properly executed.


How do you write a program to find magic numbers?

#include&lt;stdio.h&gt; unsigned sum_row (unsigned* sq, const unsigned width, const unsigned row) { unsigned sum, col; sum = 0; for (col=0; col&lt;width; ++col) sum += sq[row*width+col]; return sum; } unsigned sum_col (unsigned* sq, const unsigned width, const unsigned col) { unsigned sum, row; sum = 0; for (row=0; row&lt;width; ++row) sum += sq[row*width+col]; return sum; } unsigned sum_diag (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=0; row&lt;width; ++row, ++col) sum += sq[row*width+col]; return sum; } unsigned sum_anti (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=width-1; row&lt;width; ++row, --col) sum += sq[row*width+col]; return sum; } bool is_magic (unsigned* sq, const unsigned width) { unsigned magic, row, col; magic = sum_row (sq, width, 0); for (row=1; row&lt;width; ++row) if (magic!=sum_row(sq, width, row)) return false; for (col=0; col&lt;width; ++col) if (magic!=sum_col(sq, width, col)) return false; if (magic!=sum_diag(sq, width)) return false; if (magic!=sum_anti(sq, width)) return false; return true; } int main () { const unsigned width = 3; unsigned a[width][width] {{2,7,6},{9,5,1},{4,3,8}}; unsigned row, col; printf ("Square:\n\n"); for (row=0; row&lt;width; ++row) { for (col=0; col&lt;width; ++col) { printf ("%d ", a[row][col]); } printf ("\n"); } printf ("\n"); if (is_magic((unsigned*)&amp;a, width)) printf ("The square is magic with a magic constant of %d\n", sum_row((unsigned*)&amp;a, 3,0)); else printf ("The square is not magic\n"); return 0; }


What is an unsigned music artist called?

An unsigned artist.


What is the value of an unsigned photo of George Harrison?

Unsigned? Not much.


When was The Unsigned Guide created?

The Unsigned Guide was created in 2003.


What is an unsigned integer?

Having an unsigned integer means that the integer is positive, and not negative; literally, the integer is unsigned and assumed to be positive. The unsigned integer 8 is positive-eight, not negative-eight.


C plus plus program to list all Armstrong number?

#include&lt;iostream&gt; #include&lt;vector&gt; unsigned count_digits (unsigned num, const unsigned base=10) { unsigned count=1; while (num/=base) ++count; return count; } class number { std::vector&lt;unsigned&gt; value; unsigned base; public: number (const unsigned _value, const unsigned _base=10): value {}, base {_base} { *this = _value; } number&amp; operator= (const unsigned _value); operator unsigned () const; bool is_narcissistic () const; }; number&amp; number::operator= (unsigned _value) { unsigned count = count_digits (_value, base); value.resize (count); while (count) { value[value.size()-count--] = _value%base; _value/=base; } return *this; } number::operator unsigned () const { unsigned num = 0; for (unsigned index=0; index&lt;value.size(); ++index) num += value[index]*static_cast&lt;unsigned&gt;(std::pow (base, index)); return num; } bool number::is_narcissistic () const { unsigned num = 0; for (unsigned index=0; index&lt;value.size(); ++index) num += static_cast&lt;unsigned&gt;(std::pow (value[index], value.size())); return num == static_cast&lt;unsigned&gt; (*this); } unsigned main() { const unsigned min=1; const unsigned max=100; std::cout &lt;&lt; "Narcissistic numbers in the range " &lt;&lt; min &lt;&lt; " through " &lt;&lt; max &lt;&lt; ":\n\t"; for (unsigned n=min; n&lt;=max; ++n) if (number(n).is_narcissistic()) std::cout &lt;&lt; n &lt;&lt; ' '; std::cout &lt;&lt; '\n' &lt;&lt; std::endl; }


Is unsigned int var valid in java?

No. Java uses no unsigned numbers.


Is unsigned integer constant are available in Java?

yes use the final keyword, normally variables declared final use all capital letters but this is not required final int A = 10;


How do you attach parity bit in c language?

for example: unsigned char attach (unsigned char byte, unsigned char bit) { unsigned char mybyte; mybyte = byte&amp;0x7f; if (bit) mybyte |= 0x80; return mybyte; }


What if -1 is assigned to a unsigned variable in C plus plus?

If you assign -1 to a unsigned variable it will contain the biggest number its able to hold. For example if you assign -1 to a unsigned int it will be 4294967295 as its the biggest number a unsigned int can hold.