Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4771

IsPowerOf2 always return true

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Unknown Unknown
    • None
    • 2.21.0
    • BSON
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

    Description

      Summary

      The function IsPowerOf2 from the PowerOf2.cs file in Bson project always return true :

      • 1 & 0 = 0
      • 0 & 1 = 0

      Simple Fix:

      ```cs

      # Replace

      var result = (n & (n - 1)) == 0;

      # By

      var result = n % 2 == 0;

      ```

      Attachments

        Activity

          People

            Unassigned Unassigned
            melvin.courjaud@e-i.com Melvin Courjaud
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: