code: private function IPv6MaskToByteArray($subnetMask)
      {
          $addr = str_repeat("f", $subnetMask / 4);
          switch ($subnetMask % 4) {
              case 0:
                  break;
              case 1:
                  $addr .= "8";
                  break;
              case 2:
                  $addr .= "c";
                  break;
              case 3:
                  $addr .= "e";
                  break;
          }
          $addr = str_pad($addr, 32, '0');
          $addr = pack("H*", $addr);
  
          return $addr;
      }
docs: inspired by: http://stackoverflow.com/questions/7951061/matching-ipv6-address-to-a-cidr-subnet