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)

170 questions
101
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
  • 17,528
  • 19
  • 61
  • 80
76
votes
7 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
  • 9,020
  • 6
  • 44
  • 80
60
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,463
  • 3
  • 20
  • 35
39
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
  • 475
  • 5
  • 14
22
votes
4 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
  • 371
  • 2
  • 3
  • 11
21
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,633
  • 14
  • 48
  • 79
14
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
  • 954
  • 4
  • 15
  • 33
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
  • 106,283
  • 107
  • 420
  • 616
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
  • 11,507
  • 7
  • 65
  • 97
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
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,221
  • 3
  • 12
  • 25
9
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
  • 106,283
  • 107
  • 420
  • 616
9
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,179
  • 7
  • 35
  • 64
6
votes
6 answers

C# convert string to uint

So, I have a string of 13 characters. string str = "HELLOWORLDZZZ"; and I need to store this as ASCII representation (hex) in a uint variable. How do I do this?
Andy Hin
  • 25,283
  • 37
  • 95
  • 135
6
votes
3 answers

Mapping a ulong to a long in C#?

I am trying to map a ulong to a long (and vice-versa), and a uint to a int (and vice-versa), as shown below - in order to save the values in a MS-SQL-database with signed types integer and biginteger only. I do this because I have to check (in the…
user7212775
1
2 3
11 12