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

Post History

75%
+4 −0
Challenges Make my value binary

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

posted 3y ago by celtschk‭  ·  edited 3y ago by celtschk‭

Answer
#2: Post edited by user avatar celtschk‭ · 2021-09-03T07:47:23Z (over 3 years ago)
Adopted improvement by @Lundin
  • # [C (gcc)], 35 bytes
  • <!-- language-all: lang-c -->
  • f(n){if(n)f(n/2);printf("%i",n%2);}
  • This solution exploits that leading zeros, while not required, are also not forbidden by the task.
  • [Try it online!][TIO-kszud5n4]
  • [C (gcc)]: https://gcc.gnu.org/
  • [TIO-kszud5n4]: https://tio.run/##S9ZNT07@/z9NI0@zOhNEArG@kaZ1QVFmXkmahpJqppJOnipQoPY/UEAhNzEzT0OTq5pLQSFNwwChLCZPSdMaLGiITdAUq0ojbKLGWA0wMbA0wxQvSi0pLcpTMLDmquX6DwA "C (gcc) – Try It Online"
  • # [C (gcc)], <s>35</s> 32 bytes
  • Saved 3 bytes thanks to [Lundin](https://codegolf.codidact.com/comments/thread/4298#comment-13170)
  • <!-- language-all: lang-c -->
  • 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!][TIO-kt41w33d]
  • [C (gcc)]: https://gcc.gnu.org/
  • [TIO-kt41w33d]: https://tio.run/##S9ZNT07@/z9NI0@zOk9NDUjrG2laF5SWJGckFmnkqRnWmFhoWtf@z8wrUchNzMzT0OSq5lJQSNMwAKoqAoqmaSjF5ClpWoMFDbEJmmJVaYRN1BirASYGlmaY4kWpJaVFeQoG1ly1XP8B "C (gcc) – Try It Online"
#1: Initial revision by user avatar celtschk‭ · 2021-08-31T09:06:59Z (over 3 years ago)
# [C (gcc)], 35 bytes

<!-- language-all: lang-c -->

    f(n){if(n)f(n/2);printf("%i",n%2);}

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

[Try it online!][TIO-kszud5n4]

[C (gcc)]: https://gcc.gnu.org/
[TIO-kszud5n4]: https://tio.run/##S9ZNT07@/z9NI0@zOhNEArG@kaZ1QVFmXkmahpJqppJOnipQoPY/UEAhNzEzT0OTq5pLQSFNwwChLCZPSdMaLGiITdAUq0ojbKLGWA0wMbA0wxQvSi0pLcpTMLDmquX6DwA "C (gcc) – Try It Online"