Convert an integer to a binary string with leading zeros

11 is binary representation of 3. The binary representation of this value is 2 bits.

3 = 20 * 1 + 21 * 1

You can use String.PadLeft(Int, Char) method to add these zeros.

// convert number 3 to binary string. 
// And pad '0' to the left until string will be not less then 4 characters
Convert.ToString(3, 2).PadLeft(4, '0') // 0011
Convert.ToString(3, 2).PadLeft(8, '0') // 00000011

Leave a Comment

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