What is binary literals in c#?
When we want to deal with the binary values in C#, there is a feature named as Binary Literals. By using this feature, we can store binary values in variables.
C# provides 0b and 0x literals to create binary and hexadecimal value respectively. C# compiler recognizes these literals and treats values accordingly.
Example:
using System; namespace BinaryLiterals { class BinaryLiteralsClass { public static void Main() { // Creating binary literals int binaryvariable1 = 0b1000; // Creating hexadecimal literals int binaryvariable2 = 0x00B; Console.WriteLine(binaryvariable1); Console.WriteLine(binaryvariable2); } } }
Output:
8 11