How to get binary representation of Int in Kotlin

Method 1:
Use Integer.toBinaryString(a) where a is an Int. This method is from the Java platform and can be used in Kotlin.
Find more about this method at https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#toBinaryString(int)

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)