C# (.NET Core), 28+13=41 bytes
n=>n-(1<<(int)Math.Log(n,2))
All credit for this answer goes to NieDzejkob; the mathematical approach is significantly better than binary string manipulation (below).
C# (.NET Core), 86+13=99 bytes
n=>{var t=Convert.ToString(n,2).Remove(0,1);return t.Length<1?0:Convert.ToInt32(t,2);}
+13 bytes for using System;
###UnGolfed###
n=>{
var t = Convert.ToString(n,2).Remove(0,1);
return t.Length < 1 ? 0
: Convert.ToInt32(t,2);
}
Unfortunately Convert.ToInt32 throws an exception on "", instead of returning 0.
Ayb4btu
- 571
- 1
- 4
- 7