Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f95b751

Browse files
committed
move bit manipulation to c
1 parent 313f441 commit f95b751

File tree

13 files changed

+11
-240
lines changed

13 files changed

+11
-240
lines changed

‎snippets/cpp/bit-manipulation/check-power-of-two.md renamed to ‎snippets/c/bit-manipulation/check-power-of-two.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ tags: bit-manipulation, power-of-two
55
author: ashukr07
66
---
77

8-
```cpp
8+
```c
9+
#include <stdbool.h> // Include the standard boolean library
10+
911
bool is_power_of_two(int n) {
10-
return n > 0 && (n & (n - 1)) == 0;
12+
return n > 0 && (n & (n - 1)) == 0; // Bitwise check for power of two
1113
}
1214

1315
// Usage:

‎snippets/cpp/bit-manipulation/reverse-bits.md renamed to ‎snippets/c/bit-manipulation/reverse-bits.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
title: Reverse Bits
3-
description: Reverses the bits of a given integer.
3+
description: Reverses the bits of a given unsigned integer.
44
tags: bit-manipulation, reverse-bits
55
author: ashukr07
66
---
77

8-
```cpp
8+
```c
99
unsigned int reverse_bits(unsigned int n) {
1010
unsigned int result = 0;
1111
for (int i = 0; i < 32; ++i) {
12-
result <<= 1;
13-
result |= n & 1;
14-
n >>= 1;
12+
result <<= 1; // Shift result left by 1
13+
result |= n & 1; // Add the least significant bit of n to result
14+
n >>= 1; // Shift n right by 1
1515
}
1616
return result;
1717
}

‎snippets/cpp/bit-manipulation/xor-of-range.md renamed to ‎snippets/c/bit-manipulation/xor-of-range.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tags: bit-manipulation, xor
55
author: ashukr07
66
---
77

8-
```cpp
8+
```c
99
int xor_upto_n(int n) {
1010
if (n % 4 == 0) return n;
1111
if (n % 4 == 1) return 1;
@@ -15,4 +15,4 @@ int xor_upto_n(int n) {
1515

1616
// Usage:
1717
xor_upto_n(5); // Returns: 1 (1 ^ 2 ^ 3 ^ 4 ^ 5 = 1)
18-
```
18+
```

‎snippets/cpp/bit-manipulation/count-set-bits.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎snippets/cpp/math-and-numbers/gcd.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎snippets/cpp/math-and-numbers/lcm.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎snippets/cpp/searching/binary-search.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎snippets/cpp/searching/linear-search.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎snippets/cpp/sorting/bubble-sort.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎snippets/cpp/sorting/insertion-sort.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /