Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Clearing the most significant bit from an integer

Input

The input is a single positive integer n

Output

The output isn with its most significant bit set to 0.

Test Cases

1 -> 0
2 -> 0
10 -> 2
16 -> 0
100 -> 36
267 -> 11
350 -> 94
500 -> 244

For example: 350 in binary is 101011110. Setting its most significant bit (i.e. the leftmost 1 bit) to 0 turns it into 001011110 which is equivalent to the decimal integer 94, the output. This is OEIS A053645.

Answer*

Draft saved
Draft discarded
Cancel
3
  • 2
    \$\begingroup\$ b¦C also works... doesn't it? Convert to binary, MSB is always at index 1, remove MSB, convert back. \$\endgroup\$ Commented Nov 15, 2017 at 12:01
  • 3
    \$\begingroup\$ @MagicOctopusUrn No that is wrong, fails for 1! \$\endgroup\$ Commented Nov 15, 2017 at 12:15
  • \$\begingroup\$ @MagicOctopusUrn b¦C works for 1 in the new 05AB1E version. Although I like your .²óo- more tbh. :) \$\endgroup\$ Commented Sep 22, 2022 at 14:05

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