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 ?

forum.test17
  • 2,119
  • 6
  • 30
  • 62

3 Answers3

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.

pstanton
  • 35,033
  • 24
  • 126
  • 168
Paco Abato
  • 3,920
  • 4
  • 31
  • 54
  • Hey thanks paco , now i feel very foolish. By the way how can I know latest questions java. So that I can help others. – forum.test17 Feb 27 '15 at 09:10
  • Clic the tag Java under your question or better: write `[java]` in the Stack Overlow's search box. – Paco Abato Feb 27 '15 at 09:11
  • any desktop app regarding this in mac, or some rss feeds, any how thanks for the help – forum.test17 Feb 27 '15 at 09:21
  • You should [accept](http://meta.stackexchange.com/a/5235/281502) 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](http://stackoverflow.com/help/whats-reputation) for you and the one that answered. – Paco Abato Feb 27 '15 at 10:15
  • 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. – forum.test17 Feb 27 '15 at 13:53
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
Jonny Henly
  • 4,023
  • 4
  • 26
  • 43
heikkim
  • 2,955
  • 2
  • 24
  • 34
0

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

try this

Community
  • 1
  • 1
  • 3
    I think this doesn't really answer the question. better just leave it as a comment – Baby Feb 27 '15 at 09:14