9
To work with hexadecimal numbers, just add 0x
in front of the number, this way:
var numeroHexa = 0xff1120;
The same goes for octal numbers, adding the 0
:
var numeroOct = 037;
But how do you declare binary numbers?
var numeroBin = ??00101
I will use this to improve calculations with bitwise operators, my intention is: avoid commenting on the binary value of each Enum:
public enum Direction
{
None = 0, //0000
Left = 1, //0001
Right = 2, //0010
Up = 4, //0100
Down = 8, //1000
}
And declare directly each value
public enum Direction
{
None = ??0000
Left = ??0001
Right = ??0010
Up = ??0100
Down = ??1000
}
It was something like this that I was looking for. I think it’s much better to say that
Down
is "3 bit discolored" than simply the magic number8
. Obrg.– anisanwesley
And for those who think this is inefficient: compiler optimization solves this question.
– Maniero