--- title: "Formatting MAC addresses in dhcpd" slug: "aa-01039" description: "The binary-to-ascii function strips leading zeroes when printing numeric values." tags: ["isc dhcp"] updated: 2018-10-25T18:39:15Z published: 2018-10-25T18:39:15Z canonical: "kb.isc.org/aa-01039" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://kb.isc.org/llms.txt > Use this file to discover all available pages before exploring further. # Formatting MAC addresses in dhcpd (or 'why does binary-to-ascii strip leading zeroes?') This question arises from time to time when an administrator uses binary-to-ascii in `dhcpd.conf`, hoping to obtain the hardware address of a device that has been assigned a lease. The problem is that where a component of the address has a leading zero, this zero will be omitted in the output. Here's a typical example of usage that doesn't work quite as expected: ``` set foo = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)); ``` Instead of the expected hardware address format - for example f8:0c:f3:\*\*:\*\*:\*\*, foo will instead contain f8:c:f3:\*\*:\*\*:\*\*. This is not a bug. The problem is that the binary-to-ascii function doesn't "know" anything about the intended use of the converted binary digits and it's unusual to include leading zeroes when printing numeric values. However, with a bit of additional manipulation it's still possible to get the desired result: ``` set foo = concat ( suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2), ":", suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,6,1))),2) ); ``` *(It operates by converting each "component" separately, adding a leading zero to it (in case one is needed); taking the last two hex characters, and then concatenating them all together again.)*