OK, lets take it apart and see what is wrong:
I'll modify the code to show the bytes of the double and all 64 bit masks.
public void DoubleinBinaereundHexa(double wert) {
int bitCount = sizeof(double) * 8;
char[] result = new char[bitCount];
Byte[] bytes = BitConverter.GetBytes(wert);
foreach (Byte b in bytes) {
Console.WriteLine(Convert.ToString(b, 2).PadLeft(8, '0'));
}
long lgValue = BitConverter.ToInt64(bytes, 0);
for (int bit = 0; bit < bitCount; ++bit) {
Console.WriteLine(Convert.ToString((1 << bit), 2).PadLeft(64, '0'));
long maskwert = lgValue & (1 << bit);
if (maskwert > 0) {
maskwert = 1;
}
result[bitCount - bit - 1] = maskwert.ToString()[0];
}
Console.WriteLine("\n\nBinaere Darstellung:");
for (int i = 0; i < 64; i++) {
if (i % 4 == 0)
Console.Write(" ");
if (result[i] == '-') {
result[i] = '1';
}
Console.Write(result[i]);
}
}
This shows that the bit masks produced by
(1 << bit)
are incorrect. In fact they are integer (32 bit) masks and (1 << 0) and (1 << 32) give the same mask. To correct this the literal value must be a long, i.e. (1L << bit).
With that modification the output is
0100 0000 0011 0010 0110 0110 0110 0110 0110 0110 0110 0110 0110 0110 0110 0110
Alan.