I'm developing code to perform an elementary cellular automata in C#. I'm working in Microsoft Visual Studio Express 2012.
Overall my code is working, but I'm have trouble when writing the results to the console.
I've written a class, "bitrep", which includes a method "brep" which takes uint as an input and returns a string which corresponds to the bit representation of that uint.
For the purpose of this problem I want the returned string to be a black (filled) squares for 1's and an white (empty) square for 0's.
class bitrep
{
private uint t = 1;
private int i = 0;
private StringBuilder val = new StringBuilder();
public string brep(uint n)
{
val.Clear();
for (i = 31; i >= 0; i--)
{
test = (t & n >> i) == 1;
if (test)
val.Append((char)9632); // Produce a solid square for 1's
else
val.Append((char)9633); // Produce an empty square for 0's.
}
return val.ToString();
}
}
When the program is run with the above code an example of the output is as follows:
???????????????■????????????????
??????????????■■■???????????????
Press any key to continue . . .
Where the solid/black squares represent 1's, but instead of white squares, 0's are being written as ?'s.
Why isn't the desired output of white squares (which has a Unicode UTF-16 (decimal) encoding 9633) for 0's showing up properly?