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 Convert to Hexadecimal

Parent

Convert to Hexadecimal

+1
−1

Challenge

Write a program that takes in a number greater than or equal to 0 and outputs its representation in hexadecimal (base 16).


Examples

0     => 0
1     => 1
10    => A
15    => F
16    => 10
107   => 6B
153   => 99
207   => CF
1000  => 3E8
10381 => 288D
48821 => BEB5

Rules

  • No built-in hexadecimal functions.
    • More generally, any base conversion function is considered to be disallowed.
  • Letters can be uppercase or lowercase.
  • It should work at least for all inputs greater than 0 up to the language's default type limit.
  • Leading zeros in the output is fine. (i.e. 000003E8 for 32-bit numbers)
  • This is [code-golf], so shortest code wins.
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?

2 comment threads

Input in integer type? (4 comments)
What defines a "Hexadecimal function"? Is it strictly a `toHex` function? Is `.toString(16)` banned? ... (6 comments)
Post
+2
−0

Vyxal, 24 bytes

16ʀẋfÞ×'ẏ16$e*∑?=;hṘk6i∑

Try it Online!

Image_alt_text

All this when just H, 16R, or even k6τ would have sufficed.

Times out for every input > 100

Explained

16ʀẋfÞ×'ẏ16$e*∑?=;hṘk6i∑­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌⁤​‎‏​⁢⁠⁡‌⁢⁡​‎‏​⁢⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁤‏⁠‎⁡⁠⁢⁡⁢‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏⁠‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏⁠‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏‏​⁡⁠⁡‌⁢⁤​‎‎⁡⁠⁢⁡⁡‏‏​⁡⁠⁡‌⁣⁡​‎‎⁡⁠⁤⁤‏⁠‏​⁡⁠⁡‌⁣⁢​‎‎⁡⁠⁢⁡⁣‏‏​⁡⁠⁡‌⁣⁣​‎‎⁡⁠⁢⁢⁡‏⁠‎⁡⁠⁢⁢⁢‏⁠‎⁡⁠⁢⁢⁣‏‏​⁡⁠⁡‌⁣⁤​‎‎⁡⁠⁢⁢⁤‏‏​⁡⁠⁡‌­
16ʀẋ                      # ‎⁡Repeat the range [0, 16) (input) times.
    f                     # ‎⁢And flatten into a single list.
     Þ×                   # ‎⁣Get every possible combination with repetition of all possible lengths.
# ‎⁤(This is why it times out for large inputs)
# ‎⁢⁡(Because it needs to be long enough to have the correct output in theory)
       '         ;        # ‎⁢⁢Keep combinations where:
        ẏ16$e*∑           # ‎⁢⁣  (x_0 * 16 ^ 0) + (x_1 * 16 ^ 1) + (x_2 * 16 ^ 2) + ...
                =         # ‎⁢⁤  equals
               ?          # ‎⁣⁡  the input
                  h       # ‎⁣⁢Get the first combination
                    k6i   # ‎⁣⁣And get the corresponding characters in the string "0123456789ABCDEF"
                       ∑  # ‎⁣⁤Join into a single string
💎

Created with the help of Luminespire.

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

1 comment thread

Possible ambiguity in the rules (2 comments)
Possible ambiguity in the rules
trichoplax‭ wrote 7 days ago

There's a comment thread that gives a different impression of the rules than the challenge specification, so I've asked for the challenge to be updated to remove any ambiguity.

Until that's done, I'm not certain whether τ is permitted. I wanted to mention this to make clear that it's not conclusively forbidden yet, to hopefully dissuade people from downvoting until the rule is clarified.

trichoplax‭ wrote 7 days ago

While I was writing that, the challenge rules were updated, which I think now excludes use of τ.