3
System.out.println(Integer.parseInt("4B5CE3D77A73",16);

throws me a number format exception. and the mac address is valid one which is generated from this site http://www.miniwebtool.com/mac-address-generator/

Do i miss something here ?

1
  • 1
    Ethernet and Wireless LAN have 6 byte (48 bit) MAC addresses while int in Java has only 32 bit. Commented Feb 19, 2018 at 16:00

3 Answers 3

9

Looks like the number is greater than what Integer can hold. Try with Long:

Long.parseLong("4B5CE3D77A73",16)

Documentation states that it throws NumberFormatException - if the string does not contain a parsable integer. Not only if the string contains invalid characters but also if the number is greater than Integer.MAX_VALUE.

Sign up to request clarification or add additional context in comments.

5 Comments

Hey thanks paco , now i feel very foolish. By the way how can I know latest questions java. So that I can help others.
Clic the tag Java under your question or better: write [java] in the Stack Overlow's search box.
any desktop app regarding this in mac, or some rss feeds, any how thanks for the help
You should accept as a valid answer any of the correct answers. So the question is marked as resolved and could help other people in the future. Also you provide of some reputation for you and the one that answered.
hey sorry paco, I am new hear, I assumed the clicking on the arrow mark is way of acception the answer @Paco. I have accepted your answer.
3

The number does not fit to an integer, which's maximum value is:

System.out.println(Integer.MAX_VALUE); // prints 2147483647

Try the following:

Long.parseLong("4B5CE3D77A73",16); // 0x4B5CE3D77A73 == 82862331624051

1 Comment

Thanks for the answer :) stack overflow is faster than asking someone behind your desk
0

i think you should convert it to hexa format. this may help you.

try this

1 Comment

I think this doesn't really answer the question. better just leave it as a comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.