hexa decimal number addition in java

input 2 hexadecimal numbers and then add them and print the result without any conversion to decimal .we have to code as we simply add them in reality

It can be done in O(n) approach where n is number of digits in hexadecimal numberâ€¦

One of the way is using if else statements and adding themâ€¦
I can explain you in a bit detail If u tell me about input format and the constraint for number of digitsâ€¦

moreover tell me If you are using abcdef or ABCDEF or it can be anything from both of themâ€¦

import java.math.BigInteger;

``````class BI
{
public static void main (String[] args) throws java.lang.Exception
{
BigInteger bi1 = new BigInteger("aBc", 16);
BigInteger bi2 = new BigInteger("DeF", 16);
System.out.println(bi3.toString(16));
}
}
``````

Why settle for hexa decimals when you can perform calculations on a 36-base number??

so do you think Biginteger class wonâ€™t convert them in any other base ?? cuz he isnâ€™t allowed to change the baseâ€¦

Yes, you can always code the whole process yourself. I just tried to point out that there is already a very useful Java library class to take care of hexadecimals and other number systems.

1 Like

Okay thatâ€™s niceâ€¦