How to convert a String Mac Address to a Byte array
arrays, java, mac-address, string
Solution
The zero is going to be implied in the byte value. Remember that 0x08 == 8. You should be able to convert your to an array of 6 bytes. Youre approach is fine, just remember that if you are going to convert this back to a string, that you need to let Java know that you want to pad each number back to 2 chars. That will put your implied zeros back in place.
Problem
I have got the String MacAddress, which i need to convert in to a byte array. Java wouldn't let me do a direct conversion throwing a numberformat exception. This is what I'm doing right now ``` clientMac[0] = (byte)Integer.parseInt(strCameraMacId.substring(0, 2)); ``` I tried doing it step by step ``` String mc = strCameraMacId.substring(0,2); int test = Integer.parseInt(mc); clientMac[0] = (byte) test; ``` But the String mc consists of a value "08" and after doing the int to byte converion im losing the zero. the mac address im trying to convert is "08-00-23-91-06-48" and I might end up losing all the zeros. will I? and has anyone got an idea regarding how to approach this issue? Thanks a lot