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*

Convert from base 10 to base 2 without built-in base conversions

Background:

You have been given an assignment to convert base 10 numbers to base 2 without using any premade base conversion functions. You can't use any imported libraries either.

Problem:

Convert an input string from base 10 (decimal) to base 2 (binary). You may not use any premade base conversion code/functions/methods, or imported libraries. Since this is , the shortest answer in bytes will win.

Input will be anything from -32768 to 32767 (include sign byte handling in your code)

Answer*

Draft saved
Draft discarded
Cancel
1
  • \$\begingroup\$ You can reduce with almost 50% by using ⎕IO←0, and returning an array of bits instead of a string: 2|⌊⎕÷2*⊖⍳16. \$\endgroup\$ Commented Jun 18, 2016 at 23:09

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