IPv4 in Binary
An IPv4 address is made of four octets — numbers from 0 to 255 separated by dots. Given an address ip in the usual decimal format, convert each octet to exactly 8 binary bits, adding leading zeroes when needed. Return the final string with the binary octets separated by dots.
Примеры
Ввод
"0.0.0.0"Вывод
"00000000.00000000.00000000.00000000"Ввод
"255.255.255.255"Вывод
"11111111.11111111.11111111.11111111"Ввод
"192.168.0.1"Вывод
"11000000.10101000.00000000.00000001"Нужно реализовать
def decimal_to_binary_ip(ip: str) -> str:
Теги
mathstrings
Kirjaudu sisään nähdäksesi palautushistorian
Kirjaudu sisäänKirjaudu sisään käyttääksesi tekoälymentoria
Kirjaudu sisäänVisible tests
1
Input
"0.0.0.0"Expected
"00000000.00000000.00000000.00000000"2
Input
"255.255.255.255"Expected
"11111111.11111111.11111111.11111111"3
Input
"192.168.0.1"Expected
"11000000.10101000.00000000.00000001"4
Input
"10.0.0.255"Expected
"00001010.00000000.00000000.11111111"5
Input
"1.2.3.4"Expected
"00000001.00000010.00000011.00000100"6
Input
"1.2.3.41.2.3.4"Expected
"00000001.00000010.00000011.00101001.00000010.00000011.00000100"Focus radio
Paused · SomaFM · Fluid