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
9
votes
1 answer

Initialize unsigned byte array using hex number

I know that unsigned byte is missing in Java Then how can I initialize the byte array using integer from 0 to 255 (in hex)? final byte assoc_resp_msg_int[] = new byte[] { 0xe3, 0x00, //APDU CHOICE Type(AareApdu) 0x00,…
Bear
  • 5,138
  • 5
  • 50
  • 80
9
votes
4 answers

Is Java's lack of unsigned primitive types a characteristic of Java the platform or Java the language?

There are questions about why Java doesn't support unsigned types and a few questions about dealing with unsigned types. I did some searching, and it appears that Scala also doesn't support unsigned data types. Is the limition in the language design…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
9
votes
2 answers

Using a typedef'd uint causes error, while "unsigned int" does not...?

For some reason, when I define a variable as "uint" instead of "unsigned int" in my program, it errors. This seems strange, because uint is typedef'd as: typedef unsigned int uint; ...so I would think that I could use the two interchangeably. To…
Paul Molodowitch
  • 1,366
  • 3
  • 12
  • 29
9
votes
3 answers

How to judge an overflow when adding signed to unsigned

I'm trying to detect the overflow when adding a signed offset to an unsigned position uint32 position; int32 offset; // it could be negative uint32 position = position+offset; How can I check whether the result is overflow or underflow? I have…
rogerz
  • 1,073
  • 9
  • 18
9
votes
5 answers

Convert unsigned byte to signed byte

Is there an easy and elegant way to convert an unsigned byte value to a signed byte value in java? For example, if all I have is the int value 240 (in binary (24 bits + 11110000) = 32bits), how can I get the signed value for this int?
Joeblackdev
  • 7,217
  • 24
  • 69
  • 106
9
votes
1 answer

Do you have to append `u` suffix to unsigned integers?

I know the u suffix means 'unsigned'. But is in necessary in the following code? uint32_t hash = 2166136261u; Is it a matter or convention? Or does it have any technical significance in this case? The value should be converted to unsigned anyway…
Aviv Cohn
  • 15,543
  • 25
  • 68
  • 131
9
votes
4 answers

Signed vs Unsigned operations in C

Very simple question: I have a program doing lots and lots of mathematical computations over ints and long longs. To fit in an extra bit, I made the long longs unsigned, since I only dealt with positive numbers, and could now get a few more…
Jeff
  • 91
  • 1
  • 2
9
votes
2 answers

How to print hex from uint32_t?

The code I have been working on requires that I print a variable of type uint32_t in hexadecimal, with a padding of 0s and minimum length 8. The code I have been using to do this so far is: printf("%08lx\n",read_word(address)); Where read_word…
Dave
  • 454
  • 1
  • 7
  • 17
9
votes
3 answers

Are there uint64 literals in Go?

I'm looking at the numeric types in Go. I want to use uint64 literals. Is this possible in Go? Here's an example of how I'd like to use uint64 literals: for i := 2; i <= k; i += 1 { // I want i to be a uint64 ... }
user3835277
9
votes
5 answers

Why are the unsigned CLR types so difficult to use in C#?

I came from a mostly C/C++ background before I began using C#. One of the things I did with my first project in C# was make a class like this class Element{ public uint Size; public ulong BigThing; } I was then mortified by the fact that this…
Earlz
  • 62,085
  • 98
  • 303
  • 499
9
votes
4 answers

bit shifting with unsigned long type produces wrong results

I'm a bit confused because I wanted to initialize a variable of type unsigned long whose size is 8 bytes on my system (on every modern system I suppose). When I want to assign 1 << 63 to the variable, I get a compiler warning however and the number…
borchero
  • 5,562
  • 8
  • 46
  • 72
9
votes
2 answers

Consensus? MySQL, Signed VS Unsigned Primary/Foreign Keys

I have seen a couple threads about what everyone was doing now a days in regards to signed vs unsigned key values. It would seem that unsigned is optimal since it allows twice the number of rows for the same cost. Are there any benefits with signed…
Parris
  • 17,833
  • 17
  • 90
  • 133
9
votes
4 answers

Unsigned versus signed numbers as indexes

Whats the rationale for using signed numbers as indexes in .Net? In Python, you can index from the end of an array by sending negative numbers, but this is not the case in .Net. It's not easy for .Net to add such a feature later as it could break…
simendsjo
  • 4,739
  • 2
  • 25
  • 53
9
votes
1 answer

How does adding MIN_VALUE compare integers as unsigned?

In Java the int type is signed, but it has a method that compares two ints as if they were unsigned: public static int compareUnsigned(int x, int y) { return compare(x + MIN_VALUE, y + MIN_VALUE); } It adds Integer.MIN_VALUE to each argument,…
Boann
  • 48,794
  • 16
  • 117
  • 146
9
votes
3 answers

How to output the absolute value of an Unsigned integer in java

I want to assign 4294967295 to a variable (2^32-1) It is obvious that I can't do that with Integer, and can do it with Long. However, I noted that Java 8 offers Unsigned Integers (at least some methods). Does any one know what the method,…
Pubudu Dodangoda
  • 2,742
  • 2
  • 22
  • 38