Questions tagged [unsigned-integer]

A specific data type that uses all its bits to represent an integer value, consequently only 0 or a positive number.

In typed languages, an unsigned integer is a specific data type that uses all its bits to represent an integer value, consequently only 0 or a positive number. It can also represent integers twice the magnitude of the signed integers for the same width since no bit is used up to indicate the sign.

591 questions
19
votes
6 answers

Binding an 'unsigned long' (uint64) in an sqlite3 statement? C++

I'm using the sqlite3 library that is available at sqlite.org. I have some unsigned longs that I would like store in a database. I do not want to construct the query myself and leave it open to some sort of injection (whether it be accidental or…
g19fanatic
  • 10,567
  • 6
  • 33
  • 63
18
votes
3 answers

Difference of using int and uint and when to use

What is the difference between using int and uint? All the examples I have seen so far are using int for integers. Any advantage of using uint? Thanks.
ThickBook
  • 389
  • 1
  • 3
  • 9
17
votes
7 answers

How to generate random 64-bit unsigned integer in C

I need generate random 64-bit unsigned integers using C. I mean, the range should be 0 to 18446744073709551615. RAND_MAX is 1073741823. I found some solutions in the links which might be possible duplicates but the answers mostly concatenates some…
Erdi İzgi
  • 1,262
  • 2
  • 15
  • 33
17
votes
3 answers

C++ Implicit Conversion (Signed + Unsigned)

I understand that, regarding implicit conversions, if we have an unsigned type operand and a signed type operand, and the type of the unsigned operand is the same as (or larger) than the type of the signed operand, the signed operand will be…
2013Asker
  • 2,008
  • 3
  • 25
  • 36
16
votes
3 answers

Python: confusion between types and dtypes

Suppose I enter: a = uint8(200) a*2 Then the result is 400, and it is recast to be of type uint16. However: a = array([200],dtype=uint8) a*2 and the result is array([144], dtype=uint8) The multiplication has been performed modulo 256, to ensure…
Alasdair
  • 1,300
  • 4
  • 16
  • 28
12
votes
4 answers

How to get an unsigned integer from a byte array in Kotlin JVM?

Kotlin 1.3 introduced unsigned integer types, but I can't seem to figure out how to get an unsigned integer from a ByteArray in Kotlin JVM. Kotlin Native has a convenient ByteArray.getUIntAt() method, but this does not exist for Kotlin JVM. val…
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
12
votes
4 answers

How to declare an unsigned 32-bit integer?

Is there a way to declare a 32-bit unsigned integer in PowerShell? I'm trying to add an unsigned (begin with 0xf) i.e. 0xff000000 + 0xAA, but it turned out to be a negative number whereas I want it to be 0xff0000AA.
Patrick
  • 4,186
  • 9
  • 32
  • 45
11
votes
3 answers

SQL Server 2008 – Unsigned Integer Data Types

I am using SQL SERVER 2008, I have a number of INT, SMALLINT fields in my various tables, And I know they all will be 0 or greater than 0 i.e. I can take them Unsigned. Is there a simple way of creating/using Unsigned data types OR will I have to…
user899055
  • 301
  • 1
  • 6
  • 17
11
votes
1 answer

how to add a negative i32 number to an usize variable?

Such as: let mut a : usize = 0xFF; a += -1; // -1 may be from other variable, so there can't be a -= 1; println!("{}", a); The output is: error[E0277]: the trait bound `usize: std::ops::Neg` is not satisfied anyway?
Excosy S.P.
  • 125
  • 1
  • 8
10
votes
2 answers

Does C++14 define the behavior of bitwise operators on the padding bits of unsigned int?

C++ standard If a C++14 implementation includes padding bits in the underlying bytes of an unsigned int , does the standard specify if bitwise operations must not be performed on padding bits ? Additionally, does the C++14 standard specify if…
10
votes
3 answers

What's a portable value for UINT_MIN?

In limits.h, there are #defines for INT_MAX and INT_MIN (and SHRT_* and LONG_* and so on), but only UINT_MAX. Should I define UINT_MIN myself? Is 0 (positive zero) a portable value?
Ariel Bold
  • 245
  • 2
  • 8
10
votes
5 answers

QSpinBox with Unsigned Int for Hex Input

There are a variety of questions written here about QSpinBox's limitation of using an int as its datatype. Often people want to display larger numbers. In my case, I want to be able to show an unsigned 32bit integer in hexadecimal. This means I'd…
user1074897
10
votes
4 answers

Adding signed and unsigned int

#include int main(void) { unsigned int a = 6; int b = -20; a + b > 6 ? puts("> 6") : puts("<= 6"); } It is clear to me how the ternary operator work in this code. I am not able to understand the addition of the signed and…
Nargis
  • 4,687
  • 1
  • 28
  • 45
9
votes
2 answers

Unsigned 32 bit integers in Javascript

How can I emulate 32bit unsiged integers without any external dependencies in Javascript? Tricks with x >>> 0 or x | 0 don't work (for multiplication, they seem to work for addition / subtraction), and doubles lose precision during multiplication.…
user1367401
  • 1,030
  • 17
  • 26
9
votes
4 answers

Casting enum definition to unsigned int

According to this SO post: What is the size of an enum in C? enum types have signed int type. I would like to convert an enum definition from signed int to unsigned int. For example, on my platform an unsigned int is 32-bits wide. I want to…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
1 2
3
39 40