我正在制作一个马程序。我有马脸,想涂一点面膜。佩戴位掩码时,只能看到马眼。首先,我必须将马脸转换为数字。为此,我有一组位,其中包括用于马脸的 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";
我怀疑转换有问题,我尝试了各种方法,例如转换为字节数组并用空格格式化字符串,但没有运气。我想知道这个问题是否可能是NP难的。