Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Make my value binary

Parent

Make my value binary

+2
−0

Challenge

What do computers understand? That's right, binary. All files are turned into binary digits when you run them, but what if I suggest giving you an int then turn it into it's binary value.

  • Take input of a non-negative decimal integer and output its binary value/form.
  • Any preceding zeros don't need to be outputted.
  • This is code-golf, so the shortest program wins. Yep, not by language.

Test Cases

n = 0
Output: 0

n = 1
Output: 1

n = 5
Output: 101

n = 12
Output: 1100

n = 31
Output: 11111

n = 4096
Output: 1000000000000
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

You didn’t answer on sandbox so I guess I’ll ask here: can we output in native formats? Like python u... (2 comments)
Post
+4
−0

C (gcc), 35 32 bytes

Saved 3 bytes thanks to Lundin

f(n){n&&f(n/2);putchar(n&1|48);}

This solution exploits that leading zeros, while not required, are also not forbidden by the task.

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

32 bytes version (1 comment)
32 bytes version
Lundin‭ wrote over 3 years ago

Same solution: f(n){n&&f(n/2);putchar(n&1|48);}