Scodec - Literal binary unsigned integer string with length specified as input?

53 Views Asked by At

raw beginner with scodec here. Does scodec provide a nice way to convert an unsigned decimal integer value to a literal binary unsigned integer string with length specified as an input, left-padding with zeroes as needed up to the specified length? If so, what would that be? Many thanks...

Sample pseudocode:
{convert(unsignedDecimalIntValue = 5, bitCount = 6) => "000101"}

1

There are 1 best solutions below

0
Christopher Brinkley On

Colt Frederickson kindly answered this on Gitter for the particular case in my example above:

BitVector.fromInt(5).takeRight(6).toBin 

Generalizing the Int arguments to the terms of my pseudocode,

BitVector.fromInt(unsignedDecimalIntValue).takeRight(bitCount).toBin