You are not logged in. Please login at to post your questions!


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

asked 21 May '18, 22:32

yashikam's gravatar image

accept rate: 0%

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...


answered 22 May '18, 00:05

l_returns's gravatar image

accept rate: 25%

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

(22 May '18, 00:11) l_returns4★
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);
        BigInteger bi3 = bi1.add(bi2);

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


answered 22 May '18, 00:43

sarthakmanna's gravatar image

accept rate: 38%

edited 22 May '18, 00:43

so do you think Biginteger class won't convert them in any other base ?? cuz he isn't allowed to change the base...

(22 May '18, 01:57) l_returns4★

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.

(22 May '18, 02:22) sarthakmanna6★

Okay that's nice...

(22 May '18, 09:49) l_returns4★

Thanks for answering

(11 Jul '18, 17:14) yashikam0★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 21 May '18, 22:32

question was seen: 134 times

last updated: 11 Jul '18, 17:14