Assignment issue with bitwise operations
<p>I am attempting to write a C# serial interface for a FPGA design I've implemented.</p>

<p>As part of the interface program I need to calculate a CRC-8 checksum.</p>

<p>I've attempted to do this on a low level(as that's the level I am more familiar with) but I am having issues.</p>

<p>The problem I am having is that assignments such as the ones on lines 91-95 (e.g. line 91: <code>TempChecksumBits[7] = ChecksumBits[6];</code>)  are not only assigning the <code>TempChecksumBits[]</code> but is also changing the <code>ChecksumBits[]</code> value.</p>

<p>Any Ideas? Your help would be very much appreciated as I am less than familiar with high level languages.</p>

<p>Regards, 
Mike</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        byte[] ReadBuffer = new byte[20];
        ReadBuffer[0] = Convert.ToByte("10000001", 2);
        ReadBuffer[1] = Convert.ToByte("00000000", 2);
        ReadBuffer[2] = Convert.ToByte("11000011", 2);
        ReadBuffer[3] = Convert.ToByte("00001111", 2);
        ReadBuffer[4] = Convert.ToByte("01010101", 2);
        ReadBuffer[5] = Convert.ToByte("00001111", 2);
        ReadBuffer[6] = Convert.ToByte("01010101", 2);
        ReadBuffer[7] = Convert.ToByte("00001111", 2);
        ReadBuffer[8] = Convert.ToByte("01010101", 2);
        ReadBuffer[9] = Convert.ToByte("00001111", 2);
        ReadBuffer[10] = Convert.ToByte("01010101", 2);
        ReadBuffer[11] = Convert.ToByte("00001111", 2);
        ReadBuffer[12] = Convert.ToByte("01010101", 2);
        ReadBuffer[13] = Convert.ToByte("00001111", 2);
        ReadBuffer[14] = Convert.ToByte("01010101", 2);
        ReadBuffer[15] = Convert.ToByte("00001111", 2);
        ReadBuffer[16] = Convert.ToByte("01010101", 2);
        ReadBuffer[17] = Convert.ToByte("00001111", 2);
        ReadBuffer[18] = Convert.ToByte("01010101", 2);
        ReadBuffer[19] = Convert.ToByte("11100111", 2);
        CheckDataPacket(ReadBuffer);

    }


           private void CheckDataPacket(byte[] ReadBuffer)
           {
               byte[] Checksum = new byte[1];
               Checksum[0] =   Convert.ToByte("00000000", 2);
               byte[] DataBytes = new byte[18];
               DataBytes[0] = ReadBuffer[2];
               DataBytes[1] = ReadBuffer[3];
               DataBytes[2] = ReadBuffer[4];
               DataBytes[3] = ReadBuffer[5];
               DataBytes[4] = ReadBuffer[6];
               DataBytes[5] = ReadBuffer[7];
               DataBytes[6] = ReadBuffer[8];
               DataBytes[7] = ReadBuffer[9];
               DataBytes[8] = ReadBuffer[10];
               DataBytes[9] = ReadBuffer[11];
               DataBytes[10] = ReadBuffer[12];
               DataBytes[11] = ReadBuffer[13];
               DataBytes[12] = ReadBuffer[14];
               DataBytes[13] = ReadBuffer[15];
               DataBytes[14] = ReadBuffer[16];
               DataBytes[15] = ReadBuffer[17];
               DataBytes[16] = ReadBuffer[18];
               DataBytes[17] = ReadBuffer[1];

               CalculateChecksum(DataBytes, ref Checksum);
               textBox1.Text = (Convert.ToString(Checksum[0]));

           }

           private void CalculateChecksum(byte[] DataBytes, ref byte[] Checksum)
           {
               BitArray ChecksumBits = new BitArray(Checksum);
               BitArray TempChecksumBits = new BitArray(Checksum);

               for (int i = 0; i &lt; 18; i++)
               {
                   byte[] CurrentByte = new byte[1];
                   CurrentByte[0] = DataBytes[i];
                   BitArray DataBits = new BitArray(CurrentByte);

                   for (int k = 0; k &lt; 8; k++)
                   {

                       TempChecksumBits[7] = ChecksumBits[6];
                       TempChecksumBits[6] = ChecksumBits[5];
                       TempChecksumBits[5] = ChecksumBits[4];
                       TempChecksumBits[4] = ChecksumBits[3];
                       TempChecksumBits[3] = ChecksumBits[2];

                       if ((ChecksumBits[7]) == (ChecksumBits[1]))
                       {
                           TempChecksumBits[2] = false;
                       }

                       else
                       {
                           TempChecksumBits[2] = true;
                       }

                       if ((ChecksumBits[7]) == (ChecksumBits[0]))
                       {
                           TempChecksumBits[1] = false;
                       }

                       else
                       {
                           TempChecksumBits[1] = true;
                       }


                       if ((DataBits[7-k]) == (ChecksumBits[7]))
                       {
                           TempChecksumBits[0] = false;
                       }

                       else
                       {
                           TempChecksumBits[0] = true;
                       }
                       ChecksumBits = TempChecksumBits;
                   }
               }
               /////////////// re-form checksum Byte/////////////////////
               for (int j = 0; j &lt; 8; j++)
               {
                   if (ChecksumBits[j] == true)
                   {
                       double Value = Math.Pow(2, j);
                       Checksum[0] += (byte)(Value);
                   }
               }
           }



    }
}
</code></pre>
