Simple Fun #319: Number And IP Address
Description:
Task
An IP address contains four numbers(0-255) and separated by dots. It can be converted to a number by this way:
Given a string s
represents a number or an IP address. Your task is to convert it to another representation(number to IP address
or IP address to number
).
You can assume that all inputs are valid.
Example
Example IP address: 10.0.3.193
Convert each number to a 8-bit binary string (may needs to pad leading zeros to the left side):
10 --> 00001010
0 --> 00000000
3 --> 00000011
193 --> 11000001
Combine these four strings: 00001010 00000000 00000011 11000001
and then convert them to a decimal number:
167773121
Input/Output
[input]
string s
A number or IP address in string format.
[output]
a string
A converted number or IP address in string format.
Example
For s = "10.0.3.193"
, the output should be "167773121"
.
For s = "167969729"
, the output should be "10.3.3.193"
.
Similar Kata:
Stats:
Created | Jun 6, 2017 |
Published | Jun 6, 2017 |
Warriors Trained | 1343 |
Total Skips | 53 |
Total Code Submissions | 3345 |
Total Times Completed | 726 |
JavaScript Completions | 241 |
Python Completions | 330 |
Java Completions | 82 |
Ruby Completions | 41 |
Kotlin Completions | 57 |
Total Stars | 32 |
% of votes with a positive feedback rating | 93% of 238 |
Total "Very Satisfied" Votes | 211 |
Total "Somewhat Satisfied" Votes | 21 |
Total "Not Satisfied" Votes | 6 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |