Convert number to standard binary or twos complement
17 April 2022 (Updated 17 May 2022)
You want a function that takes two params:
num
: number to be converted into binary or twos complement.numBits
: number of bits used to storenum
.
and returns a standard binary representation if num
is positive or two’s complement representation if num
is negative:
Here’s how:
Sources
Tagged:
Snippets
Thanks for your comment . Once it's approved, it will appear here.
Leave a comment