5

I am storing some data in Cassandra via the Datastax driver, and I have the need to store unsigned 16-bit and 32-bit integers. For unsigned 16-bit integers, I can easily store them as signed 32-bit integers and cast them as needed. For unsigned 64-bit integers, however, I am at a loss. I can store them as strings and parse them, or I can store them as byte arrays. I could store them as 64-bit signed integers and do the bit manipulation required to convert from and to 64-bit unsigned integers.

What is the recommended way?

jorgebg
  • 6,560
  • 1
  • 22
  • 31
Mark
  • 11,257
  • 11
  • 61
  • 97
  • How about `varint` and `decimal`? Are those not available from .net? – Stefan Podkowinski Mar 25 '15 at 08:49
  • Pretty crazy that cassandra doesnt support uint. I guess it shows how infrequently uint is used in real world situations or there would be enough pressure on them to support it. – Jay Sep 17 '21 at 00:15

1 Answers1

2

You can use Cassandra's varint, represented in the C# Driver as BigInteger.

You can do explicit conversions from BigInteger to ushortand ulong.

jorgebg
  • 6,560
  • 1
  • 22
  • 31
  • That's probably the best way, but `BigInteger` has performance implications relative to `ulong` :( – Mark Mar 25 '15 at 19:11
  • 1
    You can use `long` and then do `unchecked { ulong value = (ulong) longValue; }` – jorgebg Mar 26 '15 at 09:33