code conversion - Need a little more help converting a CRC function from VB.NET to C# -
I should probably put all this in one question, sorry for this: (
second error < Private static string getCRC (string input, bool attachment) {string toEnc = string.Format (" {0} {1} ", input, appendDate == true String.Format? (" {0: YYYYMMDD} ", System.DateTime.Now):" "); System.IO.MemoryStream mStream = New System.IO MemoryStream (System.Text.ASCIIEncoding.ASCII.GetBytes (toEnc), false); CRC32 oCRC = new CRC32 (); returned oCRC.GetCrc32 (((System.IO.Stream) mStream) ToString ();}}
Private static string getCRC (string input, bool attachment) {string toEnc = string.Format (" {0} {1} ", input, appendDate == true String.Format? (" {0: YYYYMMDD} ", System.DateTime.Now):" "); System.IO.MemoryStream mStream = New System.IO MemoryStream (System.Text.ASCIIEncoding.ASCII.GetBytes (toEnc), false); CRC32 oCRC = new CRC32 (); returned oCRC.GetCrc32 (((System.IO.Stream) mStream) ToString ();}}
error return line form Compiler error message: CS1502: The best overloaded method matching for CRC.CRC32 GetCrc32 (ref system.ioastream) has some invalid arguments
Here is the function that is being referenced:
Public UInt32 GetCrc32 (IE stream. Stream stream) {// Dim the form of crc32Result Integer = & amp; in; HFFFFFFFF UInt32 crc32Result = UInt32.MaxValue; Try {byte [buffer = new byte [BUFFER_SIZE]; Int readSize = BUFFER_SIZE; Int count = stream.Read (buffer, 0, read size); Int i; UInt32 iLookup; // as the IEL ut Integer = 0 while ((Count> 0)) {for (i = 0; i & lt; = count - 1; i ++) {iLookup = (crc32Result & amp; 0xff) ^ Buffer [i]; // crc32Result = ((crc32Result & amp; HFFFFFF00) & amp; H100) & amp; HFFFFFF with bad 'SHR 8: / crc32Result = ((UInt32) ((crc32Result & 4294967040L / / 256) & UInt32.MaxValue); Dirty shell 8 with vb: / crc32Result = crc32Result ^ crc32Table [iLookup]; Count = stream.Read (buffer, 0, read size); }} Hold (ex before) {HttpContext.Current.Response.Output.Write (String.Format ("{0} {1} {2}", ex.Message, Environment.NewLine, ex.StackTrace)); System.Diagnostics.Debugger.Break (); } Return (~ crc32Result); }
As you can see, I tried to put the memorystream in the form of a stream, but I do not think it is very much like it.
The first error
()
If you have not seen any of my previous questions, then I have written the CRC function on the VB net. I used an online converter on C # to convert it. Here is the original VB code:
UInt32 = 398822384 Dim as I do for the integer, I for the integer ReDim crc32Table (256) dim dwCrc as UInt32 as = 0 For public sub-new () dim dwPolynomial 255 dwCrc = I for J = 8 for 1st phase (dwCrc and 1) then dwCrc = ((dwCrc & amp; HFFFFFFE) \ 2 & amp;) and & amp; ; H7FFFFFFF dwCrc = dwCrc Xor dwPolynomial else dwcrc = ((dwCrc & amp; Amp; HFFFFFFFE) \ 2 & amp;) and & amp; H7FFFFFF end if next J CRC32Table (i) = dwCrc Next I end
Here is my changed code. I had fixed some errors that I had, but there are others that I do not understand Coming:
public CRC32 () {UInt32 dwPolynomial = ((UInt32) 3988292384L); Int i; Int j; UInt32 [] crc32Table; Crc32Table = new UInt32 [256]; UInt32 dwCrc; (I = 0; i & lt; = 255; i ++) for {dwCrc = ((UInt32) i); For (J = 8; J> = 1; J - = 1) {if ((dwcrc and 1)} {dwCrc = ((dwcrc & amp; 0xfffffffe) / 2L) & amp; 0x7FFFFFFF; DwCrc = dwCrc ^ dwPolynomial; } And (dwCrc = ((dwCrc & amp; 0xfffffffe) / 2L) & amp; 0x7FFFFFFF;}} Crc32Table [i] = dwCrc;}} The first line is on this line: Compiler Error Message: CS0030: Type 'UIT' if ((dwcrc & amp; 1))
Am I comparing these two values with a different operator? I'm also not sure why the & amp;
operator is honest
Thanks SO.
Integer-to-boolean conversion in C # You have 0 Compared with the statement must:
if ((dwcrc & amp; 1)! = 0) ...
Comments
Post a Comment