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

Return to Answer

Commonmark migration
Source Link

C# (.NET Core), (削除) 28+13=41 (削除ここまで) 35 bytes

n=>n-(1<<(int)System.Math.Log(n,2))

Try it online!

###Acknowledgements###

Acknowledgements

All credit for this answer goes to NieDzejkob; the mathematical approach is significantly better than binary string manipulation (below).

-6 bytes thanks @raznagul for seeing that System could just be included directly in the code, rather than as using System;.

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);}

Try it online!

+13 bytes for using System;

###UnGolfed###

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.

C# (.NET Core), (削除) 28+13=41 (削除ここまで) 35 bytes

n=>n-(1<<(int)System.Math.Log(n,2))

Try it online!

###Acknowledgements###

All credit for this answer goes to NieDzejkob; the mathematical approach is significantly better than binary string manipulation (below).

-6 bytes thanks @raznagul for seeing that System could just be included directly in the code, rather than as using System;.

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);}

Try it online!

+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.

C# (.NET Core), (削除) 28+13=41 (削除ここまで) 35 bytes

n=>n-(1<<(int)System.Math.Log(n,2))

Try it online!

Acknowledgements

All credit for this answer goes to NieDzejkob; the mathematical approach is significantly better than binary string manipulation (below).

-6 bytes thanks @raznagul for seeing that System could just be included directly in the code, rather than as using System;.

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);}

Try it online!

+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.

added 186 characters in body
Source Link
Ayb4btu
  • 571
  • 1
  • 4
  • 7

C# (.NET Core), 28+13=41(削除) 28+13=41 (削除ここまで) 35 bytes

n=>n-(1<<(int)System.Math.Log(n,2))

Try it online! Try it online!

###Acknowledgements###

All credit for this answer goes to NieDzejkob; the mathematical approach is significantly better than binary string manipulation (below).

-6 bytes thanks @raznagul for seeing that System could just be included directly in the code, rather than as using System;.

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);}

Try it online!

+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.

C# (.NET Core), 28+13=41 bytes

n=>n-(1<<(int)Math.Log(n,2))

Try it online!

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);}

Try it online!

+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.

C# (.NET Core), (削除) 28+13=41 (削除ここまで) 35 bytes

n=>n-(1<<(int)System.Math.Log(n,2))

Try it online!

###Acknowledgements###

All credit for this answer goes to NieDzejkob; the mathematical approach is significantly better than binary string manipulation (below).

-6 bytes thanks @raznagul for seeing that System could just be included directly in the code, rather than as using System;.

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);}

Try it online!

+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.

added 650 characters in body
Source Link
Ayb4btu
  • 571
  • 1
  • 4
  • 7

C# (.NET Core), 28+13=41 bytes

n=>n-(1<<(int)Math.Log(n,2))

Try it online!

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);}

Try it online!

+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.

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);}

Try it online!

+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.

C# (.NET Core), 28+13=41 bytes

n=>n-(1<<(int)Math.Log(n,2))

Try it online!

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);}

Try it online!

+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.

added 277 characters in body
Source Link
Ayb4btu
  • 571
  • 1
  • 4
  • 7
Loading
Source Link
Ayb4btu
  • 571
  • 1
  • 4
  • 7
Loading

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