How is ethernet hardware addresses 12 digits of hex in 6 bytes?

From razwiki
Jump to navigation Jump to search

https://csguide.cs.princeton.edu/hardware/setup/enet

For example 0:40:5:1c:e:9f

9f is 2 digits of hex. Each of those digits goes from 0 to f (... 9 a b c d e f, so f is 15 even though f is the 6th letter of the alphabet it all works out)

each of those digits 9 and f can be represented in 4 bits: f would be

1111

= 1 + 2 + 4 + 8

so each hex number digit pair can be represented in one byte, which goes from 0 to 63.

There's no alphanumeric mapping for a single character to represent a byte. Rather a pair of hex numbers counts all the way from 0 to 2**8 - 1 = 255.

But let's say for example an ethernet address is all 48 bits on

ff:ff:ff:ff:ff:ff

this would be the bit pattern

1...46 ones...1 for a total of 48 ones

To represent this in hex, we say

ff ff ff ff ff ff

The lowest value ff is

15 + 16 * 15

= 160 + 80 + 15 = 255

It all works out.

One more round of practice: my ethernet ends in b6. What is that in terms of bits and bytes?

b = 11 = 8 + 2 + 1

1 0 1 1

6 = ... 6, 4 + 2

0 1 1 0

Putting them together,

10110110 = 0 + 2 + 4 + 0 + 16 + 32 + 0 + 128 = 54 + 128 = 182

and b6:

11 * 16 + 6 = 176 + 6 = 182

It all checks out.