Decimal to Hexadecimal Converter in Java

后端 未结 13 2266
有刺的猬
有刺的猬 2020-12-03 13:57

I have a homework assignment where I need to do three-way conversion between decimal, binary and hexadecimal. The function I need help with is converting a decimal into a he

相关标签:
13条回答
  • 2020-12-03 14:50

    The following converts decimal to Hexa Decimal with Time Complexity : O(n) Linear Time with out any java inbuilt function

    private static String decimalToHexaDecimal(int N) {
        char hexaDecimals[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        StringBuilder builder = new StringBuilder();
        int base= 16;
        while (N != 0) {
            int reminder = N % base;
            builder.append(hexaDecimals[reminder]);
            N = N / base;
        }
    
        return builder.reverse().toString();
    }
    
    0 讨论(0)
提交回复
热议问题