static string ipv6_as_compressed(IpBits ip_bits, BigInteger host_address) { //println!("ipv6_as_compressed:{}", host_address); var ret = new StringBuilder(); var the_colon = ":"; var the_empty = ""; var colon = the_empty; var done = false; foreach (var rle in Rle.code(ip_bits.parts(host_address))) { var abort = false; for (var i = 0; !abort && i < rle.cnt; i++) { if (done || !(rle.part == 0 && rle.max)) { ret.Append(colon); ret.Append(rle.part.ToString("x")); colon = the_colon; } else if (rle.part == 0 && rle.max) { ret.Append("::"); colon = the_empty; done = true; abort = true; } } } return(ret.ToString()); }
static string ipv6_as_uncompressed(IpBits ip_bits, BigInteger host_address) { var ret = new StringBuilder(); var sep = ""; foreach (var part in ip_bits.parts(host_address)) { ret.Append(sep); ret.Append(part.ToString("x4")); sep = ":"; } return(ret.ToString()); }