How does it do that!? An integer is an integer is an integer. Internally it is always binary, and externally is however you wish to represent it. You cannot hold a hexadecimal representation as anything other than a string, and your convert2dec() function does not take a string, it takes an integer. It also returns an int, which is not decimal ...