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
5
votes
3 answers

Why is unsigned 4 not considered greater than signed -2?

unsigned int x = 4; int y = -2; int z = x > y; When realizing this operation the value for the variable Z is 0, but why it is 0 and not 1?.
J.Doe
  • 77
  • 2
5
votes
2 answers

converting an array of signed bytes to unsigned bytes

I have a array of bytes. bytes[] = [43, 0, 0, -13, 114, -75, -2, 2, 20, 0, 0] I want to convert it to unsigned bytes in Java. this is what I did: created a new array and copy the values with & 0xFF: this.bytes = new byte[bytes.length]; for…
Ohad
  • 1,563
  • 2
  • 20
  • 44
5
votes
2 answers

Multiplication and Division unsigned integers

In my program , I have to perform arithmetic operations on unsigned integers. The variable a has a range from 0 to 4294967295. The variable b has a range from 0 to 32. When I check the boundary condition by taking the maximun values for a and b,I…
Gopala Krishna
  • 117
  • 1
  • 12
5
votes
5 answers

would doing arithmetic operation on a pair of signed and unsigned numbers be legal?

I'm more than half way through learning assembly and I'm familiar with the concept of how signed and unsigned integers are presented in bits, I know that it might seem a weird question of which the answer would be pretty obvious, but I'm wondering…
Pooria
  • 2,017
  • 1
  • 19
  • 37
5
votes
3 answers

uint8_t and unsigned char linking error

I'm using template function: template void func(const T& value) { obj->func(value); } where obj is object of class: void my_object::func(int64_t value) { ... } void my_object::func(uint64_t value) { ... } void…
mnn
  • 1,952
  • 4
  • 28
  • 51
5
votes
1 answer

Are unsigned integers standard in fortran?

In 2017, are unsigned integers in standard Fortran, or is it still a maybe not portable extension of some compilers?
Anthony Scemama
  • 1,563
  • 12
  • 19
5
votes
5 answers

What will happen if I assign negative value to an unsigned char?

In C++ primer it says that "if we assign an out of range value to an object of unsigned type the result is the remainder of the value modulo the number of values the target type can hold." It gives the example: int main(){ unsigned char i =…
vyasriday
  • 90
  • 1
  • 9
5
votes
3 answers

What is the real advantage of using unsigned variables in C++?

So I understand that unsigned variables can only hold positive values and signed variables can hold negative and positive. However, it is unclear to me why would someone use unsigned variables? Isn't that risky? I mean I would personally just stick…
Hbi Giu
  • 113
  • 1
  • 9
5
votes
1 answer

QVariant signed/unsigned comparisons

The QVariant type of the Qt Framework offers comparison operators <, <=, >, >=, but they work unexpected on signed/unsigned integer arguments mismatch: QVariant(-1) < QVariant(0u) yields false QVariant(0u) > QVariant(-1) yields false Does anybody…
jonjonas68
  • 495
  • 4
  • 13
5
votes
4 answers

Are there languages compatible with .NET that don't support unsigned types?

Let's say that I'm writing a library in C# and I don't know who is going to consume it. The public interface of the library has some unsigned types - uint, ushort. Apparently those types are not CLS-compliant and, theoretically speaking, there may…
Jivko Petiov
  • 586
  • 7
  • 15
5
votes
2 answers

Swift converting signed array of Int [int8] to unsigned array of Int [UInt8]

How to convert signed array of [Int8] to unsigned array of [UInt8]. let arryData: [Int8] = [-108, 11, -107, -14, 35, -57, -116, 118, 54, 91, 12, 67, 21, 29, -44, 111] I just want to convert this above into array of Unsigned [UInt8]. How to…
nik
  • 2,289
  • 6
  • 37
  • 60
5
votes
1 answer

C implicit conversion?

Can someone explain to me how printf("%d", -2<2u?1:-1); prints out '-1'. I assume there is some kind of implicit conversion going on but I can't seem to grasp it.
Nebeski
  • 610
  • 4
  • 14
5
votes
2 answers

Detecting if an unsigned integer overflow has occurred when adding two numbers

This is my implementation to detect if an unsigned int overflow has occurred when trying to add two numbers. The max value of unsigned int (UINT_MAX) on my system is 4294967295. int check_addition_overflow(unsigned int a, unsigned int b) { if (a…
Kingamere
  • 9,496
  • 23
  • 71
  • 110
5
votes
3 answers

Understanding Java unsigned numbers

I want to understand how to convert signed number into unsigned. lets say I have this: byte number = 127; // '1111111' In order to make it unsigned I have to choose "bigger" data type 'short' and apply AND operator with value 0x00ff. short…
shlomjmi
  • 667
  • 3
  • 12
  • 16
5
votes
2 answers

How can I safely use a Java byte as an unsigned char?

I am porting some C code that uses a lot of bit manipulation into Java. The C code operates under the assumption that int is 32 bits wide and char is 8 bits wide. There are assertions in it that check whether those assumptions are valid. I have…
Confluence
  • 1,331
  • 1
  • 10
  • 26