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

Post

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)
What defines a "Hexadecimal function"? Is it strictly a `toHex` function? Is `.toString(16)` banned? ...
ATaco‭ wrote 8 days ago

What defines a "Hexadecimal function"? Is it strictly a toHex function? Is .toString(16) banned? What about if the language implicitly outputs hexadecimal? (What about using xxd?)

CrSb0001‭ wrote 8 days ago

If it’s a builtin function that takes in a base 10 number and outputs a number in base 16 as a string or whatever, it is banned. So both toHex and .toString(16) would be banned.

As for xxd, I would say that it does not apply in the context of this challenge, as it is used primarily to create or analyze the hexdumps of files.

trichoplax‭ wrote 7 days ago

The challenge says:

No built-in hexadecimal functions.

However, this comment thread suggests a stronger rule:

.toString(16) would be banned.

Since toString can convert to different bases depending on that argument, this suggests general base conversion functions are banned.

Please could you update the rules to make unambiguous whether general base conversion functions are permitted? This way the challenge will stand alone, not dependent on reading the comments for the correct interpretation.

Currently there is an answer which complies with the challenge wording which would be forbidden by the apparent exclusion of general base conversion functions in this comment thread.

trichoplax‭ wrote 7 days ago

Ambiguity is common when designing challenge specifications. For this reason I post my challenges first to the Sandbox category so as much ambiguity as possible can be pointed out before answers start arriving. This makes it easier to make changes to the rules without invalidating answers.

CrSb0001‭ wrote 7 days ago

I've updated the ruleset in the question trichoplax‭ ATaco‭

CrSb0001‭ wrote 7 days ago

trichoplax‭ I'll keep the idea of first posting to the Sandbox in mind.