Created
April 28, 2022 19:25
-
-
Save thechriskent/5e3e18126c78f65a7439abea0fb36872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If(CountRows(binaryDigits)=0, | |
ClearCollect(binaryDigits,[]); | |
ForAll(Sequence(31,30,-1), | |
Collect(binaryDigits, { | |
index: Value, | |
worth: Power(2,Value) | |
}) | |
) | |
); | |
ClearCollect(intToBinary,[]); | |
With({ | |
firstDigit: CountRows(binaryDigits) - 1, //starting point depending on the number of binary digits | |
input: Value(txtToBinary.Text) | |
}, | |
ForAll(binaryDigits, | |
With({ | |
remainder: If(index = firstDigit, input, Last(intToBinary).remaining) //what's left to process (starts with input and decreases) | |
}, | |
Collect(intToBinary,{ | |
binary: If(remainder >= worth, "1", "0"), //Actual binary digit (left to right) | |
remaining: If(remainder >= worth, remainder - worth, remainder) //process what's left | |
}) | |
) | |
) | |
); | |
Set(binaryResult, | |
With({ | |
full: Concat(intToBinary,binary) | |
}, | |
Right(full, Len(full) - Find("1",full) + 1) //trims leading zeros (unnecessary really) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment