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
61
votes
7 answers

Comparison operation on unsigned and signed integers

See this code snippet int main() { unsigned int a = 1000; int b = -1; if (a>b) printf("A is BIG! %d\n", a-b); else printf("a is SMALL! %d\n", a-b); return 0; } This gives the output: a is SMALL: 1001 I don't understand what's happening…
Gitmo
  • 2,366
  • 5
  • 25
  • 31
60
votes
7 answers

What is the best way to work around the fact that ALL Java bytes are signed?

In Java, there is no such thing as an unsigned byte. Working with some low level code, occasionally you need to work with bytes that have unsigned values greater than 128, which causes Java to interpret them as a negative number due to the MSB being…
Max
  • 1,528
  • 1
  • 11
  • 17
58
votes
6 answers

When should I just use "int" versus more sign-specific or size-specific types?

I have a little VM for a programming language implemented in C. It supports being compiled under both 32-bit and 64-bit architectures as well as both C and C++. I'm trying to make it compile cleanly with as many warnings enabled as possible. When I…
munificent
  • 11,946
  • 2
  • 38
  • 55
50
votes
0 answers

Android Export aborted because fatal error were founds

I can't export signed or unsigned application package *Export Aborted Export aborted because fatal Lin error were founds. These are listed in the problems view. Either fix these before running Export Again, or turn off "Run full error check when…
Maskdevil
  • 521
  • 1
  • 5
  • 6
43
votes
13 answers

Can a pointer (address) ever be negative?

I have a function that I would like to be able to return special values for failure and uninitialized (it returns a pointer on success). Currently it returns NULL for failure, and -1 for uninitialized, and this seems to work... but I could be…
Jared Forsyth
  • 12,808
  • 7
  • 45
  • 54
43
votes
6 answers

Why is a negative int greater than unsigned int?

int main(void) { unsigned int y = 10; int x = – 4; if (x > y) Printf("x is greater"); else Printf("y is greater"); getch(); return (0); } Output: x is greater I thought the output would be y…
Slashr
  • 3,139
  • 6
  • 18
  • 13
42
votes
4 answers

Is there some meaningful statistical data to justify keeping signed integer arithmetic overflow undefined?

The C Standard explicitly specifies signed integer overflow as having undefined behavior. Yet most CPUs implement signed arithmetics with defined semantics for overflow (except maybe for division overflow: x / 0 and INT_MIN / -1). Compilers writers…
chqrlie
  • 131,814
  • 10
  • 121
  • 189
42
votes
4 answers

Why does len() returned a signed value?

Go's builtin len() function returns a signed int. Why wasn't a uint used instead? Is it ever possible for len() to return something negative? As far as I can tell, the answer is no: Arrays: "The number of elements is called the length and is never…
daxelrod
  • 2,499
  • 1
  • 22
  • 30
41
votes
4 answers

Difference between char and signed char in c++?

Consider the following code : #include #include int main(int argc, char* argv[]) { std::cout<<"std::is_same::value = "<::value<
Vincent
  • 57,703
  • 61
  • 205
  • 388
39
votes
2 answers

Signedness of enum in C/C99/C++/C++x/GNU C/GNU C99

Is the enum type signed or unsigned? Does the signedness of enums differ between: C/C99/ANSI C/C++/C++x/GNU C/ GNU C99? Thanks
osgx
  • 90,338
  • 53
  • 357
  • 513
38
votes
5 answers

In C, why is "signed int" faster than "unsigned int"?

In C, why is signed int faster than unsigned int? True, I know that this has been asked and answered multiple times on this website (links below). However, most people said that there is no difference. I have written code and accidentally found a…
Devyn Collier Johnson
  • 4,124
  • 3
  • 18
  • 39
34
votes
3 answers

Unsigned hexadecimal constant in C?

Does C treat hexadecimal constants (e.g. 0x23FE) as signed or unsigned integers?
Amr Bekhit
  • 4,613
  • 8
  • 34
  • 56
34
votes
1 answer

Why is std::streamsize defined as signed rather than unsigned?

According to http://en.cppreference.com/w/cpp/io/streamsize The type std::streamsize is a signed integral type used to represent the number of characters transferred in an I/O operation or the size of an I/O buffer. As far as I can imagine, a…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
34
votes
9 answers

How to get the signed integer value of a long in python?

If lv stores a long value, and the machine is 32 bits, the following code: iv = int(lv & 0xffffffff) results an iv of type long, instead of the machine's int. How can I get the (signed) int value in this case?
Paul Oyster
30
votes
2 answers

How to Install Driver with a cat file?

I have kernel driver. When installing on 32 bit systems and Windows XP and below, I had no problem and used SetupCopyOEMInf, but 64 bit drivers are required to be signed. I have signed it and I need to have a cat file with the driver copied…
SurDin
  • 3,281
  • 4
  • 26
  • 28
1
2
3
65 66