Questions tagged [unsigned-integer]

A specific data type that uses all its bits to represent an integer value, consequently only 0 or a positive number.

In typed languages, an unsigned integer is a specific data type that uses all its bits to represent an integer value, consequently only 0 or a positive number. It can also represent integers twice the magnitude of the signed integers for the same width since no bit is used up to indicate the sign.

591 questions
4
votes
1 answer

C Convert a Short Int to Unsigned Short

A short int in C contains 16 bits and the first bit represents whether or not the value is negative or positive. I have a C program that is as follows: int main() { short int v; unsigned short int uv; v = -20000; uv = v; …
RyeGuy
  • 4,213
  • 10
  • 33
  • 57
4
votes
1 answer

Unsigned integer in C++

I write the following code: #include using namespace std; int main() { unsigned int i=1; i=i-3; cout<
metasj
  • 65
  • 1
  • 7
4
votes
2 answers

Integer promotion unsigned in c++

int main() { unsigned i = 5; int j = -10; double d = i + j; long l = i + j; int k = i + j; std::cout << d << "\n"; //4.29497e+09 std::cout << l << "\n"; //4294967291 std::cout << k << "\n"; //-5 …
Praveen
  • 8,945
  • 4
  • 31
  • 49
4
votes
2 answers

Weird std::string::size() in a for loop

The program will print "Entered the loop" if I use input.size() - 1 as the for loop condition. std::string input; input = {""}; int i = 0; for (; i < input.size() - 1; ++i) { cout << "Entered the loop" << endl; } However, if I pass the value of…
lightrek
  • 951
  • 3
  • 14
  • 30
4
votes
2 answers

c++ Need for typecasting int to unsigned int

I had this code as part of a C++ project unsigned int fn() { //do some computations int value = .... if(value <= 0) return 0; return (unsigned int)value; } I don't get the need to use the cast at the last return statement…
Exuberant
  • 189
  • 2
  • 13
4
votes
1 answer

U suffix in the variable declaration

I know that if the number is followed with U suffix it is treated as unsigned. But why following program prints correct value of variable i even though it is initialized with negative value. (Compiled with gcc 4.9.2, 4.8.2, &…
Destructor
  • 14,123
  • 11
  • 61
  • 126
4
votes
1 answer

Binary operator '|' cannot be applied to operands of type 'Int' and 'UInt8'

I wish to perform simple or logic on 2 bit maps, yet Swift thinks this is wrong: let u: UInt8 = 0b1 let i: Int = 0b10 i | u // Binary operator '|' cannot be applied to operands of type 'Int' and 'UInit8' Any way to conform to type inference and…
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
4
votes
5 answers

How does C store negative numbers in signed vs unsigned integers?

Here is the example: #include int main() { int x=35; int y=-35; unsigned int z=35; unsigned int p=-35; signed int q=-35; …
A6SE
  • 260
  • 1
  • 3
  • 13
4
votes
2 answers

How do I perform a proper unsigned right shift in PHP?

Is this possible to get the same results in PHP and Javascript? Example: Javascript