Forum Discussion
Apr 19, 2024
Do you know how to convert binary numbers to decimal?
It's easy with the BIN2DEC function, but there's a limitation and an easy way to make a mistake and get a wrong result. The limitation is that it can't convert a number with more than 10 bits. If yo...
- Apr 25, 2024
I suspect DEC2BIN is now largely superseded by
= BASE(targetDec, 2) = DECIMAL(targetBin, 2)
Patrick2788
Apr 25, 2024Silver Contributor
At present I prefer this method:
=MOD(BITRSHIFT(numbers,SEQUENCE(,10,9,-1)),2)
I realize it can be done with MOD and simple division but I like the way this reads. I used this method in a project I'm working on where it needed to generate 1 million + bin elements and it performed well. It's good to give BITRSHIFT some exercise, too!
PeterBartholomew1
Apr 25, 2024Silver Contributor
I wouldn't say I prefer the proposed method, but it is more interesting and expresses key concepts with elegance.
I rather regret not using
= VSTACK(
BITLSHIFT(combination0, 1) + 1,
BITLSHIFT(combination1, 1)
)
to combine two lists of combinations, following Pascal's triangle. Timing runs showed
= VSTACK(
2 * combination0 + 1,
2 * combination1
)
to be faster.