import * as bigInt from "big-integer/BigInteger" ; import { expandIPv6Number } from "./IPv6Utils" ; import { leftPadWithZeroBit } from "./BinaryUtils" ; param num returns { string } export let bigIntegerNumberToHexadecimalString = ( num ) : string => { return num . toString ( 16 ) ; } ; param { string } hexadecimalString returns { string } export let hexadecimalStringToBinaryString = ( hexadecimalString ) : string => { let inDecimal = bigInt ( hexadecimalString , 16 ) ; return inDecimal . toString ( 2 ) ; } ; param hexadecimalString { string } export let hexadecimalStringToHexadecatetString = ( hexadecimalString ) : string => { let binaryString = hexadecimalStringToBinaryString ( hexadecimalString ) ; let length = binaryString . length ; if ( length > 16 ) { throw new Error ( "Given decimal in binary contains digits greater than an Hexadecatet" ) ; } return leftPadWithZeroBit ( binaryString , 16 ) ; } ; param hexadecimalString returns { string } export let colonHexadecimalNotationToBinaryString = ( hexadecimalString ) : string => { let expandedIPv6 = expandIPv6Number ( hexadecimalString ) ; let stringHexadecimal = expandedIPv6 . split ( ":" ) ; return stringHexadecimal . reduce ( ( binaryAsString , hexidecimal ) => { return binaryAsString . concat ( hexadecimalStringToHexadecatetString ( hexidecimal ) ) ; } , '' ) ; } ; param { string } num returns { string } export let binaryStringToHexadecimalString = ( num ) : string => { let inDecimal = bigInt ( num , 2 ) ; return inDecimal . toString ( 16 ) ; } ; param { string } hexadectetString returns { string } export let hexadectetNotationToBinaryString = ( hexadectetString ) : string => { let expand = expandIPv6Number ( hexadectetString ) ; let hexadecimals = expand . split ( ":" ) ; return hexadecimals . reduce ( ( hexadecimalAsString , hexavalue ) => { return hexadecimalAsString . concat ( leftPadWithZeroBit ( hexadecimalStringToBinaryString ( hexavalue ) , 16 ) ) ; } , '' ) ; } ;