Is there a method that can be used to get an Integer's representation in bits? For example when provided: 0 gives 0 4 gives 100 22 gives 10110
Is there a method that can be used to get an Integer's representation in bits? For example when provided: 0 gives 0 4 gives 100 22 gives 10110
Method 1:
Note: This method works for both positive and negative integers.
Method 2:
Use a.toString(2)
where a
is an Int, 2
is the radix
Note: This method only works for positive integers.