Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added blogs #1901

Closed
wants to merge 1 commit into from
Closed

Conversation

Grandhi-Harshitha
Copy link
Contributor

@Grandhi-Harshitha Grandhi-Harshitha commented Nov 6, 2024

📥 Pull Request

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (1748)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link

github-actions bot commented Nov 6, 2024

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible.). If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

@ajay-dhangar ajay-dhangar added gssoc-ext Contributions made as part of GirlScript Summer of Code Extended Edition. level1 GirlScript Summer of Code | Contributor's Levels labels Nov 7, 2024
Copy link
Owner

@ajay-dhangar ajay-dhangar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update your code based on suggestions

2. **OR (|)**: Sets each bit to 1 if one of the bits is 1.
3. **XOR (^)**: Sets each bit to 1 if only one of the bits is 1.
4. **NOT (~)**: Inverts all bits.
5. **Shift Left (<<)**: Shifts bits to the left, filling with 0s.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace << with `<<` or &lt;&lt;

3. **XOR (^)**: Sets each bit to 1 if only one of the bits is 1.
4. **NOT (~)**: Inverts all bits.
5. **Shift Left (<<)**: Shifts bits to the left, filling with 0s.
6. **Shift Right (>>)**: Shifts bits to the right, filling with the sign bit.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace >> with `>>` or &gt;&gt;

Comment on lines +51 to +54

def is_odd(n):
return (n & 1) == 1

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write within ```

Comment on lines +57 to +59

def set_bit(n, i):
return n | (1 << i)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write within ```

Comment on lines +62 to +65

def clear_bit(n, i):
return n & ~(1 << i)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write within ```

Comment on lines +78 to +84
def count_set_bits(n):
count = 0
while n:
n &= (n - 1) # Clear the least significant bit set
count += 1
return count

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write within ```

Comment on lines +86 to +87
print(count_set_bits(13)) # Output: 3 (binary: 1101)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write within ```

Comment on lines +89 to +103
public class BitManipulation {
// Count set bits in an integer
public static int countSetBits(int n) {
int count = 0;
while (n > 0) {
n &= (n - 1); // Clear the least significant bit set
count++;
}
return count;
}

public static void main(String[] args) {
System.out.println(countSetBits(13)); // Output: 3 (binary: 1101)
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write within ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gssoc-ext Contributions made as part of GirlScript Summer of Code Extended Edition. level1 GirlScript Summer of Code | Contributor's Levels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants