How to calculate 8-bit checksum of a SLIC bin file? I am reading the file like: Code: byte[] slic = File.ReadAllBytes(filename);
Code: string file = "slic.bin"; BinaryReader br = new BinaryReader(File.Open(file, FileMode.Open)); byte[] bytes = br.ReadBytes((int)br.BaseStream.Length); br.Close(); bytes[9] = 0; // reset checksum to 0 byte cs = 0; for (int i = 0; i < bytes.Length; i++) { cs += bytes; } cs *= 0XFF; // new checksum
Code: private byte checksum(String filename) { BinaryReader br = new BinaryReader(File.Open(filename, FileMode.Open)); byte[] bytes = br.ReadBytes((int)br.BaseStream.Length); br.Close(); bytes[9] = 0; // reset checksum to 0 byte cs = 0; for (int i = 0; i < bytes.Length; i++) { cs += bytes; } return cs *= 0XFF; // new checksum } Not exactly sure what this should return? i just need it to report the current 8-bit checksum of the file. It returns a value different as the one reported by winhex, eg: winhex return a 2 character value, this returns 3 characters
Ok. I misunderstood. I thought you wanted to calculate the SLIC checksum. If you want to find the existing checksum regardless of if it's correct or not then byte[9] is the value you need. This should return a 2 hex char value which will be displayed as 0X?? This is the routine I use to check if the SLICs that get reported have been trashed or not so I know it works.
Yes, it just needs to report the SLIC's current 8-bit checksum (I am rebuilding http://d-fault.nl/test/ in asp.net, so it only needs to report the checksum value) EDIT, got it working, it now displays it's current value Code: private string checksum(String filename) { BinaryReader br = new BinaryReader(File.Open(filename, FileMode.Open)); byte[] bytes = br.ReadBytes((int)br.BaseStream.Length); br.Close(); byte cs = 0; for (int i = 0; i < bytes.Length; i++) { cs += bytes; } return string.Format("{0:X2}", cs); } Most important features: Automatically corrects SLIC checksum Reports SLIC validity Reports SLIC version * Requires .Net framework 3.5 http://forums.mydigitallife.net/attachment.php?attachmentid=7686&d=1290521722 Kudos to BobSheep