Wey*_*ani 7 c# binary bit digital
我正在制作马节目.我有马脸,并希望应用一点面具.佩戴钻头面罩时,只能看到马眼.首先,我必须将马面转换为数字.为此,我有一组位,包括0,0,0和1马的脸.
我正在使用C#并将问题分解为部分:
在第4步,我希望只看到马眼,但我只看到"0",这不是一个马脸.
这是我的所有代码,请不要质疑我的ASCII艺术与问题无关,除了它是一个原型,真正的程序将具有卓越的图形.
//the head of the horse
string head = "# #" +
"########" +
"#O O#" +
"# #" +
"# #" +
"#= =#" +
" #====# " +
" #### ";
//digitize the horse into bits of binary
string binaryHead = head.Replace('#', '0').Replace('=', '0').Replace(' ', '0').Replace('O', '1');
long face = Convert.ToInt64(binaryHead, 2);
//make a bit mask with holes for the eyes
string mask = "11111111" +
"11111111" +
"10111101" +
"11111111" +
"11111111" +
"11111111" +
"11111111" +
"11111111";
//apply the bit mask using C#
long maskBits = Convert.ToInt64(mask, 2);
string eyesOnly = Convert.ToString(face & maskBits, 2);
//eyesOnly is "0"....WHAT??? It should be more than that. WHERE IS THE HORSE??
//It should look like this:
// "00000000" +
// "00000000" +
// "01000010" +
// "00000000" +
// "00000000" +
// "00000000" +
// "00000000" +
// "00000000";
Run Code Online (Sandbox Code Playgroud)
我怀疑转换有问题,我已经尝试了各种各样的事情,比如转换为字节数组并用空格格式化字符串但没有运气.我想知道这个问题是否可能是NP难的.
face并且eyesOnly没有公共的1位。除了眼睛,maskBits什么都留下。要么交换and ,要么使用运算符翻转。并给它一个更好的名称,以便清楚它是一个掩码的用途:。01~maskBitsbitmaskForNotEyes