23
4
Challenge
Here's a simple one.
Write a function or program when given a number in base 10 as input, it will return or print that number's value in Hexadecimal.
Examples
15 -> F
1000 -> 3E8
256 -> 100
Rules
- No built-in Hexadecimal functions whatsoever
- Letters may be lowercase or uppercase
- You will only need to worry about non-negative integers, no negatives or pesky decimals
- It should work with any arbitrarily large number up to language's default type's limit.
- Newline not mandatory
- As usual, this is code-golf, so shortest code measured in bytes wins!
First problem, hope you guys enjoy! – Random Guy – 2015-12-31T02:06:02.597
5Are leading zeros allowed in the output, e.g for 32bit numbers
000003E8
? – nimi – 2015-12-31T03:03:06.410Any limit on the input? – Loovjo – 2015-12-31T03:27:11.720
@Loovjo No, it should work for any arbitrarily large number. – Random Guy – 2015-12-31T06:06:36.533
@RandomGuy Even if it exceeds the language's default number type limit? – Loovjo – 2015-12-31T06:07:35.267
1@nimi Yes, that is allowed. – Random Guy – 2015-12-31T06:08:03.220
@Loovjo No, then you can be safe. – Random Guy – 2015-12-31T06:08:33.480
@RandomGuy "No, it should work for any arbitrarily large number." ... please add this requirement to the challenge definition or drop it... having said this only in a comment sure will not be seen by everyone... – None – 2015-12-31T08:24:24.050
@yeti It is now fixed! – Random Guy – 2015-12-31T16:41:19.470
@RandomGuy ... "up to language's default type limit" ... aaaahhhh... now it reads mostly harmless ... ;-) – None – 2015-12-31T17:13:11.020
What about general base conversion built-ins, like APL's
– Adám – 2015-12-31T20:21:34.577⊤
? In my answer I use APL's⊥
which (among other usages) converts from other bases to base 10... Is that acceptable?@NBZ I will allow conversions to other bases, yes. – Random Guy – 2016-01-02T23:37:37.140
1Fun fact: C++ has a hex builtin. – Matthew Roh – 2017-03-14T17:10:07.320
In the exercise there is the phrase "•Newline not mandatory" this means that the number, or the hex characters that are printed have to end with '\n' a new line ? – RosLuP – 2018-11-01T08:58:23.523