Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thechriskent/cf46bb478fdeb60385a36918da47c1f2 to your computer and use it in GitHub Desktop.
Save thechriskent/cf46bb478fdeb60385a36918da47c1f2 to your computer and use it in GitHub Desktop.
If(CountRows(binaryDigits)=0,
ClearCollect(binaryDigits,[]);
ForAll(Sequence(8,7,-1),
Collect(binaryDigits, {
index: Value,
worth: Power(2,Value)
})
)
);
ClearCollect(intToBinary,[]);
ClearCollect(asc,[]);
ForAll(Sequence(255),
With({
firstDigit: CountRows(binaryDigits) - 1, //starting point depending on the number of binary digits
input: Value,
itbOffset: CountRows(intToBinary)
},
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
})
)
);
Collect(asc,{
Num:Value,
Char:Char(Value),
Binary: With({full: Concat(LastN(intToBinary,CountRows(intToBinary)-itbOffset),binary)},Right(full,Len(full)-Find("1",full)+1))
})
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment