Questions tagged [ulong]
65 questions
19
votes
4 answers
C# equivalent of 64-bit unsigned long long in C++
I am building a DLL which will be used by C++ using COM.
Please let me know what would be the C# equivalent of C++ 64-bit unsigned long long.
Will it be ulong type in C# ?
Please confirm.
Thanks,
Gagan

Gags
- 827
- 2
- 13
- 29
16
votes
3 answers
Can T-SQL store ulong's?
I want to store a C#.NET ulong into a T-SQL database. I don't see any provisions for doing this, as the SQL bigint has the same Min/Max values as a normal long.
Is there any way I can do this? Or is catching an OverflowException my only hope?

Onion-Knight
- 3,477
- 7
- 31
- 34
12
votes
5 answers
C#: How to convert long to ulong
If i try with BitConverter,it requires a byte array and i don't have that.I have a Int32 and i want to convert it to UInt32.
In C++ there was no problem with that.

Ivan Prodanov
- 34,634
- 78
- 176
- 248
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
7
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
6
votes
1 answer
C# ulong overflow / underflow somehow allowed
I'm a little confused about the behavior of the ulong type. I understand it to be a 64-bit integer used for positive numbers (max value 18,446,744,073,709,551,615). I just started using it because I need really big positive numbers, but there's some…

SleekPanther
- 358
- 3
- 13
6
votes
3 answers
return ulong in inline-if
Is there a reason why I can't use the following code?
ulong test(int a, int b)
{
return a == b ? 0 : 1;
}
It shows me:
Cannot implicitly convert type 'int' to 'ulong'. An explicit conversion exists (are you missing a cast?)
The following will…

Marcel Niehüsener
- 651
- 5
- 15
6
votes
1 answer
calculating Fibonacci in C#
I am trying to calculate the Fibonacci sequence in C# in a very simple way, however when it comes to the higher numbers it bugs out and stops working by giving out wrong answers.
ulong num = 1;
ulong lnum = 0;
uint x = 1;
private void…

Michael Guercia
- 169
- 5
5
votes
3 answers
Why can't I assign (1<<31) to an ulong var? (Error 25 Constant value ... cannot be converted ...)
Why does this assigning produce a comile error: Constant value '-2147483648' cannot be converted to a 'ulong' and I have to use unchecked (...) for this case?
ulong xDummy30 = (1 << 30); // works
ulong xDummy31 = (1 << 31); // ERROR 25 Constant…

marsh-wiggle
- 2,508
- 3
- 35
- 52
4
votes
1 answer
C# date types convertion same as c++
How do I convert ulong to long with same result as I get in c++.
C++
unsigned long ul = 3633091313;
long l = (long)ul;
l is -661875983
C#
ulong ul = 3633091313;
long l = (long)ul;
l is 3633091313

Teamol
- 733
- 1
- 14
- 42
4
votes
3 answers
Parallel.For with 64-bit unsigned indexes (UInt64)
In C#, there's a System.Threading.Tasks.Parallel.For(...) which does the same as a for loop, without order, but in multiple threads.
The thing is, it works only on long and int, I want to work with ulong. Okay, I can typecast but I have some trouble…

phogl
- 494
- 1
- 8
- 16
4
votes
1 answer
Strange C# platform invoke / DLLImport behaviour
I have an unmanaged DLL I am referencing in my project using [DLLImport], but am receiving odd results when I match method signatures.
Here is an example signature from the DLL:
DLLEXPORT unsigned long OpenPort(unsigned long ulPort,
…

Alfie
- 2,341
- 2
- 28
- 45
3
votes
1 answer
How to reset single bit in ulong?
I have ulong number. I need to be able to quickly set and reset single bit. For example:
15 is 1111. By setting 5th bit I will get 47, so 101111
I figured it out how to set a bit:
ulong a = 15;
a |= 1 << 5; // so, now a=47
But I'm struggling how…

Louisa Bickley
- 297
- 5
- 17
3
votes
1 answer
Declaring ULONG_MAX in C
I have been doing a lot of research on ULONG_MAX and trying to find out how to declare it, but it doesn't seem to work. I using the header #include and #include

Manav Dubey - Streetsville SS
- 51
- 1
- 2
- 7
3
votes
2 answers
How do I raise a really big number to a really big power?
I have a ulong value that I need to raise to a high power, but Math.Pow does not successfully produce a correct output.
My c# code:
ulong a = 9123456789;
ulong b = (ulong)Math.Pow(a, 9999);
Console.WriteLine(b);
The output to screen is 0. How…

TaGi Asadullazadeh
- 91
- 1
- 9