Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
765 B

  1. class Program {
  2. string encode_ip(string $dotquad_ip) {
  3. string[] $ip_sep = explode('.', $dotquad_ip);
  4. return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
  5. }
  6. string decode_ip(string $int_ip) {
  7. string[] $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
  8. return hexdec($hexipbang[0]) + '.' + hexdec($hexipbang[1]) + '.' + hexdec($hexipbang[2]) + '.' + hexdec($hexipbang[3]);
  9. }
  10. public void main() {
  11. string $localhost = $this->encode_ip('127.0.0.1');
  12. print("127.0.0.1 ==> $localhost\n");
  13. string $router = $this->encode_ip('192.168.2.1');
  14. print("192.168.2.1 ==> $router\n");
  15. print("$localhost ==> ", $this->decode_ip($localhost) + PHP_EOL);
  16. print("$router ==> ", $this->decode_ip($router) + PHP_EOL);
  17. }
  18. }