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
15
votes
2 answers

Why does std::bitset suggest more available bits than sizeof says there are?

I'm working on some simple bit manipulation problems in C++, and came across this while trying to visualize my steps. I understand that the number of bits assigned to different primitive types may vary from system to system. For my machine,…
jonthalpy
  • 1,042
  • 8
  • 22
15
votes
1 answer

(unsigned) byte in GLSL

Some of my vertex attributes are single unsigned bytes, I need them in my GLSL fragment shader, not for any "real" calculations, but for comparing them (like enums if you will). I didnt find any unsigned byte or even byte data type in GLSL, so is…
l'arbre
  • 719
  • 2
  • 10
  • 29
15
votes
5 answers

Gcc: force compiler to use unsigned char by default

Since the nature of a char in C++ is compiler-dependent when the unsigned qualifier is not present, is there an argument I could pass on to GCC which would force all chars to be compiled as unsigned?
user2233125
15
votes
2 answers

Why do MIPS operations on unsigned numbers give signed results?

When I try working on unsigned integers in MIPS, the result of every operation I do remains signed (that is, the integers are all in 2's complement), even though every operation I perform is an unsigned one: addu, multu and so fourth... When I print…
dankilman
  • 886
  • 2
  • 9
  • 18
15
votes
6 answers

unsigned char to int in C++

I have a variable unsigned char that contains a value, 40 for example. I want a int variable to get that value. What's the simplest and most efficient way to do that? Thank you very much.
user1346664
  • 189
  • 1
  • 1
  • 8
14
votes
8 answers

For loop condition to stop at 0 when using unsigned integers?

I have a loop that has to go from N to 0 (inclusively). My i variable is of type size_t which is usually unsigned. I am currently using the following code: for (size_t i = N; i != (size_t) -1; --i) { ... } Is that correct? Is there a better…
gnuvince
  • 2,357
  • 20
  • 27
13
votes
5 answers

difference between printing a memory address using %u and %d in C?

I reading a C book. To print out a memory address of a variable, sometimes the book uses: printf("%u\n",&n); Sometimes, the author wrote: printf("%d\n",&n); The result is always the same, but I do not understand the differences between the two (I…
ipkiss
  • 13,311
  • 33
  • 88
  • 123
13
votes
1 answer

Unsigned Int in Java

I'm trying to implement an existing network protocol which makes heavy use of Unsigned datatypes, which are not supported by Java. What I currently do is for each datatype, chose the next bigger one so that the unsigned number may fit into the…
cdecker
  • 4,515
  • 8
  • 46
  • 75
13
votes
4 answers

What is the difference between signed and unsigned binary

I've been reading a few sites, but none of them make sense to me. Is signed and unsigned binary them same as signed and unsigned variables. I'd be glad if you could help :)
R.M.R
  • 193
  • 1
  • 2
  • 9
13
votes
8 answers

Compute the absolute difference between unsigned integers using SSE

In C is there a branch-less technique to compute the absolute difference between two unsigned ints? For example given the variables a and b, I would like the value 2 for cases when a=3, b=5 or b=3, a=5. Ideally I would also like to be able to…
Jack Nock
  • 14,703
  • 5
  • 22
  • 18
13
votes
5 answers

SQlite: Column format for unix timestamp; Integer types

Original problem: What is the right column format for a unix timestamp? The net is full of confusion: some posts claim SQLite has no unsigned types - either whatsoever, or with exception of the 64bit int type (but there are (counter-)examples that…
SF.
  • 13,549
  • 14
  • 71
  • 107
13
votes
4 answers

1's complement using ~ in C/C++

I am using Visual Studio 2013. Recently I tried the ~ operator for 1's complement: int a = 10; cout << ~a << endl; Output is -11 But for unsigned int a = 10; cout << ~a << endl; the output is 4294967296 I don't get why the output is -11 in the…
user2912611
  • 534
  • 2
  • 6
  • 16
13
votes
3 answers

unsigned integer field in django

Any idea how to use an unsigned integer field in Django? By this I mean a field inside a model with a range from 0 to 4294967295 and stores 32 bit. This definition excludes the PositiveIntegerField because it only has a range from 0 to 2147483647. I…
Vjeetje
  • 5,314
  • 5
  • 35
  • 57
13
votes
3 answers

Why int plus uint returns uint?

int plus unsigned int returns an unsigned int. Should it be so? Consider this code: #include #include #include class test { static const int si = 0; …
Vahagn
  • 4,670
  • 9
  • 43
  • 72
12
votes
5 answers

Why is uint_least16_t faster than uint_fast16_t for multiplication in x86_64?

The C standard is quite unclear about the uint_fast*_t family of types. On a gcc-4.4.4 linux x86_64 system, the types uint_fast16_t and uint_fast32_t are both 8 bytes in size. However, multiplication of 8-byte numbers seems to be fairly slower than…