Questions tagged [unsigned]

An unsigned variable is a variable that can only represent non-negative numbers.

An unsigned variable is a variable that can only represent non-negative numbers, as opposed to a signed variable which can represent both positive and negative numbers.

1251 questions
6
votes
4 answers

Why "unsigned int64_t" gives an error in C?

Why the following program gives an error? #include int main() { unsigned int64_t i = 12; printf("%lld\n", i); return 0; } Error: In function 'main': 5:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'i' …
msc
  • 33,420
  • 29
  • 119
  • 214
6
votes
3 answers

How to pass integer as unsigned parameter in VB.NET?

I'm using a library call, setInstance(ByVal instance As UInteger), in my VB.NET code. The parameter I need to pass is an Integer. Is there anything I need to do to convert the integer parameter to an unsigned integer? The number is guaranteed to be…
CodeFusionMobile
  • 14,812
  • 25
  • 102
  • 140
6
votes
2 answers

Simulating unsigned number with a certain power of two max in java

I have some output from a (C++) application that stores a tickcount value in a type that wraps to zero at 233. (8,589,934,592) (Don't have the code) I need to write my own output in the same way. I retrieve the tickcount from a C lib through JNA,…
Alex
  • 631
  • 1
  • 8
  • 33
6
votes
2 answers

get amazon web service unsigned URLs in c#

I m using amazon sdk for .net i have uploaded a file in folder of my bucket , now i want to get the url of that file using this code GetPreSignedUrlRequest request = new GetPreSignedUrlRequest(); request.BucketName = "my-new-bucket2"; …
Ahtesham ul haq
  • 319
  • 1
  • 5
  • 14
6
votes
1 answer

C++ explain casting uint64 to uint32

I'm trying to cast a uint64_t (representing time in nanoseconds from D-day using a boost chrono high precision clock) to a uint32_t in order to seed a random number generator. I just want the least significant 32 bits of the uint64_t. Here is my…
Salmonstrikes
  • 737
  • 1
  • 6
  • 25
6
votes
2 answers

Why this C program outputs a negative number?

I have assigned the complement value in an unsigned variable. Then why this C program outputs a negative number? #include #include int main() { unsigned int Value = 4; /* 4 = 0000 0000 0000 0100 */ unsigned…
user366312
  • 16,949
  • 65
  • 235
  • 452
6
votes
1 answer

operator << interprets arithmetic operation if the result is unsigned int or unsigned short

I use gcc 4.8.3 under fedora 19 64bits unsigned u1=10, u2=42; unsigned short us1=10, us2=42; int main() { cout << "u1-u2="<
axel
  • 61
  • 1
6
votes
3 answers

How to find out if a variable is signed or unsigned?

In a C implementation that uses 2's complement integers, if an signed integer is negative, then the highest bit is 1, otherwise 0. Lets take char and unsigned char, the range for a signed char is -128 to 127 and unsigned char is 0 to 255, but in…
6
votes
2 answers

Is this a VC compiler bug? About unsigned integer wrapping

I think the C program below shall output 1: #include int main() { unsigned int n=18u; while ((n+17u)>=17u) n-=17u; printf("%u\n",n+17u); return 0; } But compiled in VC6, Visual Studio 2010, or Visual Studio 2012, all in…
zwhconst
  • 1,352
  • 9
  • 19
6
votes
2 answers

How to get a 16bit Unsigned integer in python

I currently read off pixels from an image using python PIL. These pixels are 16bit greyscale and are unsigned. However, whenever PIL reads them in it thinks they are signed and makes values that should be something like 45179 into -20357. org_Image…
Marmstrong
  • 1,686
  • 7
  • 30
  • 54
6
votes
3 answers

c++ vector size. why -1 is greater than zero

Please take a look at this simple program: #include #include using namespace std; int main() { vector a; std::cout << "vector size " << a.size() << std::endl; int b = -1; if (b < a.size()) std::cout << "Less"; else …
Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
6
votes
2 answers

iOS - int (unsigned int) maximum value is 2147483647, unsigned int doesn't work?

the maximum value for an 32-Bit integer is: 2^31-1 = 2147483647. but just with negative and positive number. because the half of the number is negative. so the real maximum value is 2^32-1 = 4294967295. but in this case we just use positive…
Jonathan Gurebo
  • 169
  • 2
  • 3
  • 9
6
votes
3 answers

How to print unsigned char* in NSLog()

Title pretty much says everything. would like to print (NOT in decimal), but in unsigned char value (HEX). example unsigned char data[6] = {70,AF,80,1A, 01,7E}; NSLog(@"?",data); //need this output : 70 AF 80 1A 01 7E Any idea? Thanks in advance.
HelmiB
  • 12,303
  • 5
  • 41
  • 68
6
votes
3 answers

Binary search algorithm turns up error - Use of unassigned local variable

I was following a tutorial showing how to create a Binary search algorithm from scratch. However I recieve the error "Use of unassigned local variable 'Pivot'". I'm new to the language and have only tried much simpler languages previously. I…
Matthew Morgan
  • 199
  • 2
  • 10
6
votes
5 answers

C++ How to check that a function is receiving an unsigned int?

I have a function declared as: void foo(unsigned int x) How can I check that foo() is not receiving negative numbers? I'd like that if I call foo(-1) an exception is thrown, but of course since x is converted automatically to unsigned, I can't…
lucacerone
  • 9,859
  • 13
  • 52
  • 80