見習村13 - int32 to IPv4
13 - int32 to IPv4
Don’t say so much, just coding…
Instruction
Take the following IPv4 address: 128.32.10.1
This address has 4 octets where each octet is a single byte (or 8 bits).
- 1st octet 128 has the binary representation:
10000000
- 2nd octet 32 has the binary representation:
00100000
- 3rd octet 10 has the binary representation:
00001010
- 4th octet 1 has the binary representation:
00000001
So 128.32.10.1
== 10000000.00100000.00001010.00000001
Because the above IP address has 32 bits, we can represent it as the unsigned 32 bit number: 2149583361
Complete the function that takes an unsigned 32 bit number and returns a string representation of its IPv4 address.
Examples
1 |
|
Ruby
Init
1 |
|
Sample Testing
1 |
|
Javascript
Init
1 |
|
Sample Testing
1 |
|
Thinking
想法(1): 先需要去了解 IPv4 是什麼
想法(2): 轉為 binary
後還要 8
個為一群,並且補 0
Hint & Reference
- Ruby
- JavaScript
Solution
Ruby
1 |
|
Javascript
1 |
|