Modify array by removing characters from their Hexadecimal representations which are present in a given string | Function to convert a decimal number to its equivalent hexadecimal number ; Function to convert hexadecimal number to its equavalent decimal number ; Stores characters with their respective hexadecimal values ; Stores answer ; Traverse the string ; If digit ; If character ; Return the answer ; Function to move all the alphabets to front ; Function to modify each array element by removing characters from their hexadecimal representation which are present in a given string ; Traverse the array ; Stores hexadecimal value ; Remove the characters from hexadecimal representation present in string S ; Stores decimal value ; Replace array element ; Print the modified array ; Given array ; Given string ; Function call to modify array by given operations
def decHex ( n ) : NEW_LINE INDENT alpha = [ ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' ] NEW_LINE ans = ' ' NEW_LINE while n : NEW_LINE INDENT if n % 16 < 10 : NEW_LINE INDENT ans += str ( n % 16 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans += alpha [ n % 16 - 10 ] NEW_LINE DEDENT n //= 16 NEW_LINE DEDENT ans = ans [ : : - 1 ] NEW_LINE return ans NEW_LINE DEDENT def hexDec ( convertedHex ) : NEW_LINE INDENT mp = { " A " : 10 , " B " : 11 , " C " : 12 , " D " : 13 , " E " : 14 , " F " : 15 } NEW_LINE ans = 0 NEW_LINE pos = 0 NEW_LINE for i in convertedHex [ : : - 1 ] : NEW_LINE INDENT if i . isdigit ( ) : NEW_LINE INDENT ans += ( 16 ** pos ) * int ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT ans += ( 16 ** pos ) * mp [ i ] NEW_LINE DEDENT pos += 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT def removeChars ( hexaVal , S ) : NEW_LINE INDENT setk = set ( ) NEW_LINE for i in S : NEW_LINE INDENT setk . add ( i ) NEW_LINE DEDENT ans = ' ' NEW_LINE for i in hexaVal : NEW_LINE INDENT if i in setk : NEW_LINE INDENT continue NEW_LINE DEDENT ans += i NEW_LINE DEDENT return ans NEW_LINE DEDENT def convertArr ( arr , S ) : NEW_LINE INDENT for i in range ( len ( arr ) ) : NEW_LINE INDENT hexaVal = decHex ( arr [ i ] ) NEW_LINE convertedHex = removeChars ( hexaVal , S ) NEW_LINE decVal = hexDec ( convertedHex ) NEW_LINE arr [ i ] = decVal NEW_LINE DEDENT print ( arr ) NEW_LINE DEDENT arr = [ 74 , 91 , 31 , 122 ] NEW_LINE S = "1AB " NEW_LINE convertArr ( arr , S ) NEW_LINE