1
Convert a binary number (of any size) into a hexadecimal number.
Input
A POSITIVE binary number with just the 0
s and 1
s. A valid input will always match the following regex: [0-1]+
. If the input is not a valid binary number, that is, anything not matching this regex, the output should be 0
or the program should exit, or error. The output does not need the leading 0x
nor does it need to be capitalized.
Output
The binary number converted to hexadecimal.
Winning
Original Code-Golf Rules, Lowest amount of bytes.
Examples
IN: [101]
OUT: [0x5] OR [5]
IN: [10000000010100100000]
OUT: [0x80520] OR [80520]
IN: [1010101]
OUT: [0x55] OR [55]
IN: [1111111111111111]
OUT: [0xFFFF] OR [FFFF] OR [0xffff] OR [ffff]
IN: [1012101]
OUT: [0]
IN: [a]
OUT: [0]
IN: [-1010101]
OUT: [0]
IN: [abcdef]
OUT: [0]
IN: [2]
OUT: [0]
12Boo-urns to input validation! – Shaggy – 2017-08-27T20:19:54.737
2Can we exit if the input isn't valid binary? – caird coinheringaahing – 2017-08-27T20:20:59.357
@cairdcoinheringaahing Yes – Hashim Kayani – 2017-08-27T20:39:41.547
2This should be popularity contest or something, not code golf. – Titus – 2017-08-27T21:11:38.010
@Titus popularity-contest would be a lot better – dv02 – 2017-08-27T21:24:57.267
6@DirtyDev Popularity contest would NOT better. – Level River St – 2017-08-27T21:29:32.507
...note how many answers do not conform to the input validation requirements - this is one of the reasons to just not have such restrictions in code-golf. – Jonathan Allan – 2017-08-27T23:11:48.047
11You could shave one byte off your regex:
[01]+
– martin – 2017-08-28T02:10:37.0631@Titus This would be closed instantly as a pop con. – Dennis – 2017-08-28T05:45:24.373
75 hours was far too quick to an accept a solution, especially one that does not meet the specs on invalid input. – Shaggy – 2017-08-28T09:32:20.433
In tcl, these regexp is not enough to exclude
-1010101
, may be because the-
is the parameter indicator, example:regexp -expanded ...
– sergiol – 2017-11-20T00:03:44.573I wish there was a "boring" close-vote reason, the "input validation" part of this spec really ruins the challenge. – MD XF – 2017-12-23T04:16:50.397