c# - tilde `~` use in Enum -
iv'e through answer.
can not seem understand line of code:
i'm trying many cultures can.
cultureinfo[] cinfo = cultureinfo.getcultures(culturetypes.allcultures & ~culturetypes.neutralcultures); public enum culturetypes { neutralcultures = 1, specificcultures = 2, installedwin32cultures = 4, allcultures = 7, usercustomculture = 8, replacementcultures = 16, [obsolete("this value has been deprecated. please use other values in culturetypes.")] windowsonlycultures = 32, [obsolete("this value has been deprecated. please use other values in culturetypes.")] frameworkcultures = 64, }
does tilde makes constructor behave this?:
cultureinfo[] cinfo = cultureinfo.getcultures(culturetypes.allcultures | culturetypes.neutralcultures | culturetypes.specificcultures | culturetypes.installedwin32cultures | culturetypes.usercustomculture | culturetypes.replacementcultures );
this expression:
culturetypes.allcultures & ~culturetypes.neutralcultures
is equivalent (in natural language) of: "allcultures except neutralcultures".
the bitwise complement operator ~
negate value of culturetypes.neutralcultures
.
let's bitwise math manually:
allcultures = 0111 // 1+2+4=7 neutralcultures = 0001 // 1 specificcultures = 0010 // 2 installedwin32cultures = 0100 // 4
so:
~neutralcultures = 1110 // bits flipped
and:
allcultures & ~neutralcultures = 0111 & 1110
which results in:
0111 1110 ---- 0110
0110
6 in decimal, equivalent specificcultures | installedwin32cultures
Comments
Post a Comment