Click here to Skip to main content
14,269,076 members
Rate this:
Please Sign up or sign in to vote.
See more:
int crc_register ;


if (crc_register & 0x0001)
{
crc_register = crc_register >> 1;
crc_register = crc_register ^ 0xa001;
}
else
{
crc_register = crc_register >> 1;
}

What I have tried:

Cannot implicitly convert type 'int' to 'bool'
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

When you find code on the internet in one language and try to use it in another, you have to understand three things:
1) The source language - in this case C or C++
2) The destination language - in this case C#
3) What the code does, and how it does it.

C and C++ look a lot like C# (understandable, C# was heavily influenced by them when it was designed) but they are very, very different languages which share some common syntax. You can't just lift C code and assume it will work unchanged in C#!

In this case, C does not have a concept of boolean values - no true or false. Instead, it treats any non-zero value as true, and any zero value as false. C# does have boolean values, and enforces their use.
So this:
if (crc_register & 0x0001)
needs to be changed to this:
if ((crc_register & 0x0001) != 0)

But ... you cannot expect the code even when it compiles to work exactly the same as the original unless you comply with all three of the conditions above!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100