How can I pass the MAC address to Ethernet shield with leading zeroes?

I change the default MAC address from DEADBEEFFEED to something like DEADBEEFFE01. So I only change the last number from 0xED to 0x01. My board is communicating to a separate server and when I look at the MAC in that server, my board is listed as DEADBEEFFE1.

It's not as simple as printing the MAC address with padded zeroes as the board is actually removing it.

I've looked at the Ethernet library and I saw that the mac is passed as an array of uint8_t. I think that's why, the last number is read as 1 (which is correct) but passed as just that.

Is there a way for the MAC to pass leading zeroes?

  • 2
    0x01 is 1. the server prints it wrong
    – Juraj
    Oct 23, 2020 at 6:43
  • Yep, apparently, found out that it is the server that has a problem.
    – noobiejp
    Oct 23, 2020 at 15:39

1 Answer 1


Writing this in case someone in the future might be interested.

The values passed in the Ethernet library is correct. The last value, 0x01 must be 1 and is written correctly, 0x01 in the registers of the W5500 inside the Ethernet shield.

Where I've got it wrong is how I pass the MAC address to the server. I'm basically creating a string for a json message. In there, I've put %02x to make sure that zeroes are padded.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.