I decided to implement double dabble algorithm to convert binary of any side into decimal representation and vice versa. Practically, there’s a limit, but I honestly doubt you’ll reach that limit.
Source: Double dabble - Wikipedia
However, it seems that I have a problem here:
C:\Windows\System32>gmic rep_bin2dec_dd 1111111011011100 echo ${}
[gmic]./ Start G'MIC interpreter (v.3.3.3).
9,8,2,4,4
[gmic]./ End G'MIC interpreter.
As you can see, it’s suppose to be 6,5,2,4,4 in the end result. So, some digits shows up correctly, others do not.
#@cli rep_bin2dec_dd:
#@cli : Convert binary numbers to digit representation using the double dabble method. Large binary number is supported here.
rep_bin2dec_dd:
$=arg
repeat $# {
p:=$>+1
('${arg$p}')
if im<_'0'||iM>_'1' error inv_char_det fi
-. {'0'}
if (w<=53)&&0
eval[-1] <begin(m=0;n=0;);n|=i<<m;++m;end(set('\{\}',n);); rm.
else
eval "
const max_dec_digits=ceil(w#-1*log10(2));
const bit_mask=15; # equal to 1111
const msd_cond=7; # equal to 111
const shift_above=4; # If a value is greater than 4, then add 3.
dec_out_vec=vector(#max_dec_digits);
last_pos=0;
repeat(w#-1,p,
for(q=last_pos,q>-1,--q,
dec_out_vec[q]<<=1;
if(q
,dec_out_vec[q]|=dec_out_vec[q-1]>>3;
,dec_out_vec[q]|=i[#-1,p]);
dec_out_vec[q]&=bit_mask;
if(dec_out_vec[q]>4,
print(reverse(dec_out_vec));
dec_out_vec[q]+=3;
);
dec_out_vec[q]&=bit_mask;
print(reverse(dec_out_vec));
if(q==last_pos?dec_out_vec[q]>msd_cond,++last_pos;);
);
);
reverse(dec_out_vec);"
fi
}
rm.