Questions tagged [signed]

In computing, signedness is a property of data types representing numbers in computer programs.

A numeric variable is signed if it can represent both positive and negative numbers, and unsigned if it can only represent non-negative numbers (zero or positive numbers).

As signed numbers can represent negative numbers, they lose a range of positive numbers that can only be represented with unsigned numbers of the same size (in bits) because roughly half the possible values are non-positive values. Unsigned variables can dedicate all the possible values to the positive number range.

For example, a Two's complement signed 16-bit integer can hold the values −32768 to 32767 inclusively, while an unsigned 16 bit integer can hold the values 0 to 65535. For this sign representation method, the leftmost bit (most significant bit) denotes whether the value is positive or negative (0 for positive, 1 for negative).

Reference

980 questions
30
votes
9 answers

What does it mean for a char to be signed?

Given that signed and unsigned ints use the same registers, etc., and just interpret bit patterns differently, and C chars are basically just 8-bit ints, what's the difference between signed and unsigned chars in C? I understand that the signedness…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
30
votes
4 answers

Why is (18446744073709551615 == -1) true?

When I was working on string::npos I noticed something and I couldn't find any explanation for it on the web. (string::npos == ULONG_MAX) and (string::npos == -1) are true. So I tried this: (18446744073709551615 == -1) which is also true. How…
Bahadır
  • 454
  • 1
  • 4
  • 8
29
votes
4 answers

Signed vs. unsigned integers for lengths/counts

For representing a length or count variable, is it better to use signed or unsigned integers? It seems to me that C++ STL tends to prefer unsigned (std::size_t, like in std::vector::size(), instead C# BCL tends to prefer signed integers (like in…
user1149224
24
votes
4 answers

How to enable compiler warning when comparing char and unsigned char?

take for example the following C code : int main(int argc, char *argv[]) { signed char i; unsigned char count = 0xFF; for (i=0; i
sagi
  • 523
  • 3
  • 15
21
votes
6 answers

Would it break the language or existing code if we'd add safe signed/unsigned compares to C/C++?

After reading this question on signed/unsigned compares (they come up every couple of days I'd say): Signed / unsigned comparison and -Wall I wondered why we don't have proper signed unsigned compares and instead this horrible mess? Take the…
Nordic Mainframe
  • 28,058
  • 10
  • 66
  • 83
21
votes
4 answers

Android Studio Signed APK Not Installing

I am in Android Studio and signing an APK under Build > Generate Signed APK and using the wizard. Everything appears to sign fine and an .apk file is generated. When I go copy this file over to my device (either Nexus 7 or Moto X) it won't install.…
James Miller
  • 213
  • 1
  • 2
  • 6
21
votes
2 answers

What is the minimum value of a 32-bit signed integer?

What is the minimum value of a 32-bit signed integer, happens to be the security "challenge" question in order to make an account at [this website](edit: link is now malware) (don't judge I'm just curious and bored). I assumed they were talking…
java
  • 1,319
  • 6
  • 15
  • 30
20
votes
2 answers

What is the meaning of "producing negative zeroes" in a system that doesn't support it?

C17 6.2.6.2/4 says: If the implementation does not support negative zeros, the behavior of the &, |, ^, ~, <<, and >> operators with operands that would produce such a value is undefined. If I have a 2's complement system, it does not support…
Lundin
  • 195,001
  • 40
  • 254
  • 396
19
votes
4 answers

What is happening in "? :"? I have no idea about the return type

I think ((1 ? (int)1 : (unsigned int)2) > -1) results in 1 (true), but actually it is 0 (false) in Visual Studio 2017. I think the value of (1 ? (int)1 : (unsigned int)2) should be (int)1, because 1 ? is true, and 1 > -1 would be true. I don't know…
BellSnow
  • 209
  • 1
  • 5
19
votes
1 answer

Amazon AWS S3 signed URL via Wget

I am able to create an Amazon S3 signed URL for a bucket in my account from which I can download and upload via the Amazon AWS CLI. I have created the Amazon S3 URL as follows: from boto.s3.connection import S3Connection key =…
mg03
  • 667
  • 2
  • 9
  • 14
18
votes
1 answer

"Do you want to run this application" JNLP dialog - conditions for the dialog to be shown again

A user is running a JNLP app which is launched from the browser. The *.jar file launched by the JNLP is signed by a Certificate issued by a trusted CA. For the first time the jar file is launched, the user is asked a question whether he trusts the…
user93353
  • 13,733
  • 8
  • 60
  • 122
18
votes
3 answers

Verifying that C / C++ signed right shift is arithmetic for a particular compiler?

According to the C / C++ standard (see this link), the >> operator in C and C++ is not necessarily an arithmetic shift for signed numbers. It is up to the compiler implementation whether 0's (logical) or the sign bit (arithmetic) are shifted in as…
Adisak
  • 6,708
  • 38
  • 46
18
votes
4 answers

What is zero-width bit field

Possible Duplicate: Practical Use of Zero-Length Bitfields Why some structures have zero-width bit fields, and why is it required? struct foo { int a:3; int b:2; int :0; // Force alignment to next boundary. int c:4; int …
manav m-n
  • 11,136
  • 23
  • 74
  • 97
18
votes
3 answers

How computer distinguish an integer is signed or unsigned?

Two's complements is set to make it easier for computer to compute the substraction of two numbers. But how computer distinguish an integer is signed integer or unsigned integer? It's just 0 and 1 in its memory. For exmaple, 1111 1111 in the…
viperchaos
  • 395
  • 1
  • 4
  • 15
17
votes
2 answers

How to detect negative number assigned to size_t?

This declaration compiles without warnings in g++ -pedantic -Wall (version 4.6.3): std::size_t foo = -42; Less visibly bogus is declaring a function with a size_t argument, and calling it with a negative value. Can such a function protect against…
Camille Goudeseune
  • 2,934
  • 2
  • 35
  • 56
1 2
3
65 66