28
2
Challenge
Write a program or function that converts a 32 bit binary number to its quad-dotted decimal notation (often used for representing IPv4)
Quad-dotted decimal
A quad-dotted decimal is formed like so:
- Split the binary representation into its 4 individual bytes
- Convert each byte into denary
- place "." between each number
Example:
input: 10001011111100010111110001111110
step 1: 10001011 11110001 01111100 01111110
step 2: 139 241 124 126
step 3: 139.241.124.126
I/O examples
input --> output
10001011111100010111110001111110 --> 139.241.124.126
00000000000000000000000000000000 --> 0.0.0.0
01111111000000000000000000000001 --> 127.0.0.1
11000000101010000000000111111111 --> 192.168.1.255
Rules
- Input will always be a 32 bit binary number or a binary list or string
- Standard I/O rules apply
- No standard loopholes
- This is code-golf, so the shortest answer in bytes wins
6Input will always be a 32 bit binary number but your examples are binary lists. Is that also an acceptable input form? – Adám – 2020-01-10T12:49:28.280
2Is it allowed to use a string as input instead of a list of binary digits? – Galen Ivanov – 2020-01-10T13:31:13.217
I have added a brief description of how the qaud-dotted notation is formed @LuisMendo. – mabel – 2020-01-10T13:31:50.783
@Adám this is actually how I meant for the challenge to be interpreted, but I guess I couldn't find the right word. I have added it as an acceptable input form, but left the 32 bit binary number as valid input also. – mabel – 2020-01-10T13:33:01.067
@GalenIvanov yes, I will edit the post to reflect this as well. – mabel – 2020-01-10T13:33:58.023
2I'm not clear, can we take in an actual number as input, like 2130706433 to give
127.0.0.1
? – xnor – 2020-01-11T04:00:44.743Is a trailing space or newline allowed? – ElPedro – 2020-01-11T09:05:46.343
seeing as I wrote that originally, I will allow it @xnor – mabel – 2020-01-11T13:07:44.110
that is fine @ElPedro – mabel – 2020-01-11T13:08:27.443