I am trying to have a number convert to the binary number in order to take substrings of the binary for doing a Red,Green,Blue decimal value in expressions. I’ve almost got it, but needed the leading zeros. I am using the numberFormat which mostly works, but ran into something unexpected. the following number toBinary(2939647) works just fine and yields 1011001101101011111111 missing the first two zero’s, however the following "numberFormat(toBinary(2939647),“000000000000000000000000”) yields

001011001101101011200000 which is not correct. the numberFormat rounded up to 2 for some reason. Does anyone have a better way to convert to a binary representation and have the correct number of bits showing?

toBinary already returns a string, so I wouldn’t expect numberFormat to work correctly with it.

You’d probably need to take the result of toBinary and concat the right number of leading zeros based on the length of the string.

1 Like

Yeah that’s what I was going to try next. Thank you.

Here’s what I ended up doing that worked. Thanks for the help.

if(len(toBinary(Number))=24,toBinary(Number),

concat(repeat(‘0’,24-len(toBinary(Number))),toBinary(Number)))

1 Like

Maybe more clear, almost certainly a lot faster:

`replace(stringFormat("%24s", toBinary({Root Container.Spinner.intValue})), " ", "0")`

1 Like