Click here to Skip to main content
15,892,537 members
Home / Discussions / C#
   

C#

 
AnswerRe: C++ to CSharp Pin
Covean17-Feb-10 1:28
Covean17-Feb-10 1:28 
AnswerRe: C++ to CSharp Pin
hammerstein0517-Feb-10 1:29
hammerstein0517-Feb-10 1:29 
AnswerRe: C++ to CSharp Pin
OriginalGriff17-Feb-10 1:32
mveOriginalGriff17-Feb-10 1:32 
GeneralRe: C++ to CSharp [modified] Pin
Xmen Real 17-Feb-10 1:36
professional Xmen Real 17-Feb-10 1:36 
GeneralRe: C++ to CSharp Pin
hammerstein0517-Feb-10 1:41
hammerstein0517-Feb-10 1:41 
GeneralRe: C++ to CSharp Pin
OriginalGriff17-Feb-10 1:42
mveOriginalGriff17-Feb-10 1:42 
GeneralRe: C++ to CSharp [modified] Pin
Xmen Real 17-Feb-10 1:49
professional Xmen Real 17-Feb-10 1:49 
GeneralRe: C++ to CSharp Pin
OriginalGriff17-Feb-10 3:11
mveOriginalGriff17-Feb-10 3:11 
Xmen W.K. wrote:
OriginalGriff wrote:
And please, don't use "magic numbers" - they make code really difficult to follow and maintain.
where ??


public static uint CRCRC(string text)
 {
     uint retHash = 0;
     int a = 0;
     byte[] bytes = System.Text.Encoding.ASCII.GetBytes(text);

     if (bytes[0] == 34)
         a = 1;

     for (; a < bytes.Length; a++)
     {
         byte val = bytes[a];
         if (val == 34)
             break;
         if (val - 65 > 25)
         {
             if (val == 92)
                 val = 47;
         }
         else
             val += 32;
         retHash = (1025 * (retHash + val) >> 6) ^ 1025 * (retHash + val);
     }
     return 32769 * (9 * retHash ^ (9 * retHash >> 11));
 }
34, 65, 25, 92, 47, 32 - these are all "magic numbers". Wiki - see Unnamed numerical constants here.[^] So called because they are necessary to the code but there is no explanation as to what the hell they are or do!
Looking at the original C++ code there is also a magic number 32769 - why? Does this have anything to do with the length of an int?
I am not convinced that the original code actually works (or even compiles): what is textLen[i] doing? textLen is a size_t (which is an unsigned int) not an array.

Try this[^] - I don't know that it works, I haven't tried it, but it is at least written in C# and looks like a CRC32 algorithm!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace

GeneralRe: C++ to CSharp Pin
Xmen Real 17-Feb-10 3:17
professional Xmen Real 17-Feb-10 3:17 
GeneralRe: C++ to CSharp Pin
OriginalGriff17-Feb-10 3:32
mveOriginalGriff17-Feb-10 3:32 
GeneralRe: C++ to CSharp Pin
Xmen Real 17-Feb-10 15:46
professional Xmen Real 17-Feb-10 15:46 
GeneralRe: C++ to CSharp [modified] Pin
OriginalGriff17-Feb-10 22:11
mveOriginalGriff17-Feb-10 22:11 
GeneralRe: C++ to CSharp Pin
Xmen Real 18-Feb-10 2:16
professional Xmen Real 18-Feb-10 2:16 
GeneralRe: C++ to CSharp Pin
OriginalGriff18-Feb-10 2:30
mveOriginalGriff18-Feb-10 2:30 
GeneralRe: C++ to CSharp Pin
Xmen Real 18-Feb-10 2:33
professional Xmen Real 18-Feb-10 2:33 
AnswerRe: C++ to CSharp Pin
Richard MacCutchan17-Feb-10 3:13
mveRichard MacCutchan17-Feb-10 3:13 
AnswerRe: C++ to CSharp Pin
Saksida Bojan17-Feb-10 3:26
Saksida Bojan17-Feb-10 3:26 
GeneralRe: C++ to CSharp Pin
Xmen Real 17-Feb-10 3:27
professional Xmen Real 17-Feb-10 3:27 
QuestionError Comes at showing the Crystal Report Pin
BalasubramanianK17-Feb-10 0:59
BalasubramanianK17-Feb-10 0:59 
AnswerRe: Error Comes at showing the Crystal Report Pin
Richard MacCutchan17-Feb-10 1:02
mveRichard MacCutchan17-Feb-10 1:02 
GeneralRe: Error Comes at showing the Crystal Report [modified] Pin
BalasubramanianK17-Feb-10 1:13
BalasubramanianK17-Feb-10 1:13 
GeneralRe: Error Comes at showing the Crystal Report Pin
Richard MacCutchan17-Feb-10 2:51
mveRichard MacCutchan17-Feb-10 2:51 
QuestionAccessing XML File on Web Pin
alexthecat200017-Feb-10 0:40
alexthecat200017-Feb-10 0:40 
AnswerRe: Accessing XML File on Web Pin
Michael Bookatz17-Feb-10 0:53
Michael Bookatz17-Feb-10 0:53 
GeneralRe: Accessing XML File on Web Pin
alexthecat200017-Feb-10 11:06
alexthecat200017-Feb-10 11:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.