Questions tagged [uint]

is a type of variable and is used to store the equivalent of a mathematical non-negative integer

Due to the limited amount of memory a computer can handle, uint can represent just a subset of positive integers.

In C the uint standard is unsigned int and uses 4 bytes of memory (and thus can represents all integers int the range 0 to 4,294,967,295)

192 questions
108
votes
5 answers

Why is Array.Length an int, and not an uint

Why is Array.Length an int, and not a uint. This bothers me (just a bit) because a length value can never be negative. This also forced me to use an int for a length-property on my own class, because when you specify an int-value, this needs to be…
doekman
  • 18,750
  • 20
  • 65
  • 86
105
votes
8 answers

Get Unix timestamp with C++

How do I get a uint unix timestamp in C++? I've googled a bit and it seems that most methods are looking for more convoluted ways to represent time. Can't I just get it as a uint?
2rs2ts
  • 10,662
  • 10
  • 51
  • 95
65
votes
6 answers

Difference between uint and unsigned int?

Is there any difference between uint and unsigned int? I'm looking in this site, but all questions refer to C# or C++. I'd like an answer about the C language. If it is relevant, note that I'm using GCC under Linux.
the_candyman
  • 1,563
  • 4
  • 22
  • 36
40
votes
3 answers

unsigned int (c++) vs uint (c#)

Following is the c# code: static void Main(string[] args) { uint y = 12; int x = -2; if (x > y) Console.WriteLine("x is greater"); else Console.WriteLine("y is greater"); } and this…
Samir Lakhani
  • 485
  • 6
  • 14
27
votes
3 answers

Printing a void* variable in C

Hi all I want to do a debug with printf. But I don't know how to print the "out" variable. Before the return, I want to print this value, but its type is void* . int hexstr2raw(char *in, void *out) { char c; uint32_t i = 0; uint8_t *b =…
sharkbait
  • 2,980
  • 16
  • 51
  • 89
26
votes
5 answers

Generate random uint

I need to generate random numbers with range for byte, ushort, sbyte, short, int, and uint. I am able to generate for all those types using the Random method in C# (e.g. values.Add((int)(random.Next(int.MinValue + 3, int.MaxValue - 2)));) except for…
jaqui
  • 411
  • 2
  • 5
  • 11
18
votes
1 answer

Convert Uint8ClampedArray to regular array

How can I convert a Uint8ClampedArray (like one used for storing HTML5 canvas image data) to a regular array, in which values won't be constrained to 0-255?
cincplug
  • 1,024
  • 5
  • 20
  • 38
11
votes
1 answer

Why isn't Array.count a UInt?

Why isn't Array.count a UInt instead of an Int? How could Array.count ever be negative?
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
11
votes
1 answer

C++11 uint types vs u_int

I just stumbled upon the type u_int8_t because it did not compile in Windows+MinGW (but compiled fine under Linux). According to this site the C++11 standard defines the type uint8_t. I just used the latter and everything worked. The questions that…
masgo
  • 480
  • 1
  • 5
  • 20
10
votes
5 answers

Use uint or int

Definitely, I know the basic differences between unsigned integers (uint) and signed integers (int). I noticed that in .NET public classes, a property called Length is always using signed integers. Maybe this is because unsigned integers are not CLS…
Peter Lee
  • 12,931
  • 11
  • 73
  • 100
10
votes
3 answers

C# overflow behavior for unchecked uint

I've been testing this code at https://dotnetfiddle.net/: using System; public class Program { const float scale = 64 * 1024; public static void Main() { Console.WriteLine(unchecked((uint)(ulong)(1.2 * scale *…
Lukas
  • 103
  • 3
10
votes
5 answers

Swift: How to convert String to UInt?

According to Swift - Converting String to Int, there's a String method toInt(). But, there's no toUInt() method. So, how to convert a String to a Uint?
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
10
votes
4 answers

What is the best way to combine two uints into a ulong in c#

What is the best way to combine two uints into a ulong in c#, setting the high/low uints. I know bitshifting can do it, but I don't know the syntax, or there maybe other APIs to help like BitConverter, but I don't see a method that does what I want.
Jason Coyne
  • 6,509
  • 8
  • 40
  • 70
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
8
votes
1 answer

can I assume that sizeof(uint8_t) = 1?

I have a program that uses dynamic allocation for a uint8_t array; can I safely assume that its length will always be one byte?
Tom
  • 105
  • 1
  • 1
  • 6
1
2 3
12 13