0

I have been given some code written as a unit test for xunit. I need to use this code in my application to generate a CRC-16. How can I get the code below to return what I need?

    [Fact]
    public void ComputesCrc16FromTelegramOf8000()
    {
        var calculator = new CRC16();

        var test = StringToByteArray("8000");
        var result = calculator.ComputeHash(test, 0, test.Length);
        Assert.Equal((ushort) 0xC061, BitConverter.ToUInt16(result, 0));
    }
dynamicuser
  • 1,522
  • 3
  • 24
  • 52

1 Answers1

2

You can just add some input and return the result:

public Byte[] ComputeCrc16(string input) 
{
    var calculator = new CRC16();
    var bytes = StringToByteArray(input);

    return calculator.ComputeHash(bytes, 0, bytes.Length);
}
Starscream1984
  • 3,072
  • 1
  • 19
  • 27
  • 2
    Or rather `return calculator.ComputeHash(bytes, 0, bytes.Length)` – James Apr 04 '14 at 10:24
  • Remove the `=`, also you need to set the return type to `byte[]` – James Apr 04 '14 at 10:30
  • This works for the given question, however the CRC output is wrong. I have made a further post here for anyone interested - http://stackoverflow.com/questions/22860356/how-to-generate-a-crc-16-from-c-sharp – dynamicuser Apr 04 '14 at 10:34