I am making a horse programme. I have the horse face and wish to apply a bit mask. Only the horses eyes should be visible when it is wearing the bit mask. First I must convert the horses face to digital. For this I have a set of bits which include 0, 0, 0, and 1 for the face of the horse.
I am using C# and have broken the problem into parts:
At step 4 I expect only to see the horses eyes but I only see "0" which IS NOT EVEN A HORSE FACE.
Here is all of my code, please don't question my ASCII art it is not relevant to the question, besides it is a prototype the real program will have superior graphics.
//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";
I suspect something is wrong with the conversion, I have tried all kinds of things like converting to a byte array and formatting the string with spaces but with no luck. I am wondering if this problem might be NP-hard.
face and eyesOnly have no common 1-bits. maskBits leaves everything except for the eyes. Either swap 0 and 1, or use the ~ operator to flip maskBits. And give it a better name so that it is clear what it is a mask for: bitmaskForNotEyes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With