Introduction
In the video the best way to count, binary is proposed as the best system of counting numbers. Along with this argument is a proposal on how to say numbers in this system. First, we give names to each "double power of two", \$2^{2^n}\$ for each \$n\$.
number = symbol = spoken
============================
2^0 = 1 = "one"
2^1 = 2 = "two"
2^2 = 4 = "four"
2^4 = H = "hex"
2^8 = B = "byte"
2^16 = S = "short"
2^32 = I = "int"
2^64 = L = "long"
2^128 = O = "overlong"
2^256 = P = "byteplex"
Then, to get from a number to its spoken binary, we
Take its (big-endian) bit string and break off bits from the end equal to the number of zeros in the largest double power of two less than or equal to the number.
Use the name for the corresponding double power of two in the middle, and recursively name the left and right parts through the same procedure. If the left part is one, it is not spoken, and if the right part is zero, it is not spoken.
This system is similar to how we normally read numbers: 2004 -> 2 "thousand" 004 -> "two thousand four".
For example, 44 in binary is 101100
.
Split at four bits from the end and insert "hex", meaning \$2^4\$: 10
"hex" 1100
.
10
becomes "two" and 1100
splits into 11
"four" 00
, or "two one four".
So the final number is "two hex two one four" or 2H214
in symbols (note that this is not the recommended way of writing numbers, just speaking).
As a longer example, we have one thousand:
1111101000
11 B 11101000
2 1 B 1110 H 1000
2 1 B 11 4 10 H 10 4 00
2 1 B 2 1 4 2 H 2 4
Challenge
Your program must take a positive integer \$n\$ as input and output the string of symbols for the spoken binary of that number.
While numbers under \$2^{512}\$ are expressible in this system, you only need to handle integers up to and including \$2^{32}\$ = I
, and as such, do not need to consider L
, O
, or P
.
Standard loopholes are forbidden. As this is code-golf, shortest program wins.
Example Input and Output
1 -> 1
2 -> 2
3 -> 21
4 -> 4
5 -> 41
6 -> 42
7 -> 421
8 -> 24
9 -> 241
10 -> 242
11 -> 2421
12 -> 214
25 -> H241
44 -> 2H214
100 -> 42H4
1000 -> 21B2142H24
4294967295 -> 21421H21421B21421H21421S21421H21421B21421H21421
4294967296 -> I