Questions tagged [ulong]

63 questions
17
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
  • 627
  • 2
  • 8
  • 21
15
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,257
  • 7
  • 29
  • 34
11
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
  • 31,952
  • 74
  • 168
  • 243
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
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
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…
5
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
  • 320
  • 2
  • 11
5
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…
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
  • 409
  • 1
  • 9
  • 31
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
  • 287
  • 3
  • 15
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
3
votes
2 answers

C# System.Threading.Tasks.Parallel.For on ulong

In C#, theres a System.Threading.Tasks.Parallel.For(...) wich 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
  • 484
  • 1
  • 8
  • 15
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…
3
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
  • 1,693
  • 2
  • 23
  • 41
3
votes
2 answers

C# not supported ulong to bin/oct/dec/hex string -> Convert.ToString(ulong, base)

I would have the bin/oct/dec/hex values of ulong values as string. So I have to use convert.tostring(, base) with desired base. To support this, I cast the ulong value to long, while long is supported with convert.tostring(, base) to have the…
had
  • 1,828
  • 1
  • 12
  • 9
1
2 3 4 5