Darcy Lynch
Darcy Lynch

Reputation: 35

What is the C# equivalent to Java's 0b prefix for Integer literals?

I was just wondering this because I'm trying to store binary data in integers in C# like you can in Java by using the "0b" prefix.

Upvotes: 0

Views: 232

Answers (1)

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186668

Well, 0x is 0x:

  int sample = 0xABCD;

As for binary, there's no equivalent, but you can do conversion:

  int sample = Convert.ToInt32("1010", 2);

However, C# 6.0 probably will have 0b prefix feature:

https://msdn.microsoft.com/en-us/magazine/dn683793.aspx

Upvotes: 3

Related Questions