Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 182415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:56:08+00:00 2026-05-11T14:56:08+00:00

the line if(arg2 & 1) in C++(arg2 is DWORD) is equal to if(arg2 &

  • 0

the line ‘if(arg2 & 1)’ in C++(arg2 is DWORD) is equal to ‘if(arg2 & 1==0)’ in C#(arg2 is Uint32),right?

I am trying to translate a function from C++ to C#,but I get an error:

Operator '&' cannot be applied to operands of type 'uint' and 'bool' 

I’d be also thankful if you could see further in the whole function for any other mistakes.

C++

DWORD Func_X_4(DWORD arg1, DWORD arg2, DWORD arg3) { LARGE_INTEGER result = {1, 0}; LARGE_INTEGER temp1 = {0}; LARGE_INTEGER temp2 = {0}; LARGE_INTEGER temp3 = {0}; LARGE_INTEGER temp4 = {0}; for(int x = 0; x < 32; ++x) {     if(arg2 & 1)     {         temp1.LowPart = arg3;         temp1.HighPart = 0;         temp2.QuadPart = temp1.QuadPart * result.QuadPart;         temp3.LowPart = arg1;         temp3.HighPart = 0;         temp4.QuadPart = temp2.QuadPart % temp3.QuadPart;         result.QuadPart = temp4.QuadPart;     }     arg2 >>= 1;     temp1.LowPart = arg3;     temp1.HighPart = 0;     temp1.QuadPart *= temp1.QuadPart;     temp2.LowPart = arg1;     temp2.HighPart = 0;     temp3.QuadPart = temp1.QuadPart % temp2.QuadPart;     arg3 = temp3.LowPart;     if(!arg2)         break; } return result.LowPart; } 

Converted to C#

LARGE_INTEGER structure:

[StructLayout(LayoutKind.Explicit, Size = 8)] public struct LARGE_INTEGER {     [FieldOffset(0)]     public Int64 QuadPart;     [FieldOffset(0)]     public UInt32 LowPart;     [FieldOffset(4)]     public Int32 HighPart; } 

Function:

public static UInt32 X4(UInt32 arg1, UInt32 arg2, UInt32 arg3)     {         LARGE_INTEGER result = new LARGE_INTEGER();         result.LowPart = 1;         result.HighPart = 0;         LARGE_INTEGER temp1 = new LARGE_INTEGER();         LARGE_INTEGER temp2 = new LARGE_INTEGER();         LARGE_INTEGER temp3 = new LARGE_INTEGER();         LARGE_INTEGER temp4 = new LARGE_INTEGER();         for (int x = 0; x < 32; ++x)         {             if (arg1 & 1 ==0)             {                 temp1.LowPart = arg3;                 temp1.HighPart = 0;                 temp2.QuadPart = temp1.QuadPart * result.QuadPart;                 temp3.LowPart = arg1;                 temp3.HighPart = 0;                 temp4.QuadPart = temp2.QuadPart % temp3.QuadPart;                 result.QuadPart = temp4.QuadPart;             }             arg2 >>= 1;             temp1.LowPart = arg3;             temp1.HighPart = 0;             temp1.QuadPart *= temp1.QuadPart;             temp2.LowPart = arg1;             temp2.HighPart = 0;             temp3.QuadPart = temp1.QuadPart % temp2.QuadPart;             arg3 = temp3.LowPart;             if (arg2==0)                 break;         }         return result.LowPart;     } 

This is what I’m not sure yet:

  1. Whether a DWORD in C++ is UInt32 or Int32 in C#?
  2. if(integer & integer) means if(integer and integer ==0)? //this is where the error i described above is placed.
  3. if(!integer) means if(integer != 0)?
  4. Why operator & cannot be used logically in C# ,meaning it requires a boolean?
  5. ‘LARGE_INTEGER result = {1, 0}’ means result.lowpart is 1 and result.highpart is 0 or result.Quadpart = 1?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:56:09+00:00Added an answer on May 11, 2026 at 2:56 pm

    Where you write :

    if (arg1 & arg2==0)

    The compiler understands :

    if (arg1 & (arg2==0)) 

    You should write :

    if ((arg1 & arg2) == 0) 

    This is the way the C++ statement should be translated to C# :

    if (arg2 & 1) // C++ (arg2 is DWORD) if ((arg2 & 1) != 0) // C# (arg2 is Uint32) 

    Or, in a more generic way:

    if (Flags & FlagToCheck) // C++ if ((Flags & FlagToCheck) != 0) // C# 

    In C/C++, 0 is false, everything else is true.

    1. You should check the definition of DWORD, it should be (unsigned int), which is UInt32 in C#
    2. if (integer & integer), in C/C++ means ‘if the result of the bitwise and between the two integers is not 0’ (0 is false, everything else is true).
    3. if (!integer) means if (integer == 0) (again, 0 is false, everything else is true)
    4. in C#, like in Java I think, booleans and numbers are two different things, you can only use booleans in ‘if’ statements, there is not implicit conversion if you use an int : it won’t compile.
    5. I’ll leave this one to someone else, I’d need to test to be sure…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The line where this error was called from is this: $celkova_suma=mysql_result($c_res, 0, 0)+mysql_result($d_res, 0,
I wish to do lua prog.lua arg1 arg2 from the command line Inside prog.lua,
The line-height property usually takes care of vertical alignment, but not with inputs. Is
This line of code ((Matches)Container.DataItem).MatchID works in C# but in VB.NET, when used in
The line is function info() { emacs -eval (progn (setq Man-notify-method 'bully) (info \$1\))
I have a command line application I need to execute from my PHP web
I have a script in python that can be invoked from the command-line and
I'm trying to write a wrapper function for read() system call , using asm
I keep getting this T_STRING Parse error im not sure what it is but
From the registry, for a given file type, I get a string containing something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.