×

# hexa decimal number addition in java

 0 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 0★yashikam 0●2 accept rate: 0%

 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 1.4k●1●9 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)
 0  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); System.out.println(bi3.toString(16)); } }  Why settle for hexa decimals when you can perform calculations on a 36-base number?? answered 22 May '18, 00:43 946●1●15 accept rate: 38% 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) 1 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) Okay that's nice... (22 May '18, 09:49) Thanks for answering (11 Jul '18, 17:14) yashikam0★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×17

question asked: 21 May '18, 22:32

question was seen: 134 times

last updated: 11 Jul '18, 17:14