0

I have the dest MAC address in the format of a string: "689900112233".

This link shows how to specify the mac address as 6 separate groups of 2 hex digits: https://networking-class.readthedocs.io/en/latest/tutorials/raw_ethernet/raw_ethernet.html

How can I transform the string I have into separate hex digits (0x68, 0x99, 0x00, 0x11, 0x22, 0x33)?

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
Smiley7
  • 185
  • 1
  • 3
  • 10
  • Add a colon after each 2 characters, done. Usually you start with *binary* though, then duplicate of https://stackoverflow.com/questions/16550589/how-do-you-convert-a-mac-address-in-an-array-to-string-in-c/16550666 or https://stackoverflow.com/questions/6357031/how-do-you-convert-a-byte-array-to-a-hexadecimal-string-in-c?rq=1 – Antti Haapala -- Слава Україні Aug 20 '18 at 05:15
  • Yes, I added the missing two digits. – Smiley7 Aug 20 '18 at 05:19
  • [Duplicate of something here](https://stackoverflow.com/search?q=%5Bc%5D+convert+string+to+hex) - break down the problem (making it easier to search/research) and work on the individual pieces. – user2864740 Aug 20 '18 at 05:20
  • You want to determine the values needed for e.g. `sendbuf[tx_len++] = DEST_MAC0;` ? Note that they do not need to be hex for that, any integer value for each of the six bytes is useable, too. – Yunnosch Aug 20 '18 at 05:33
  • Yes, I want to specify the values for the sendbuf. Why do they not need to be hex? – Smiley7 Aug 20 '18 at 05:35
  • "Hex" is a string format, a way of serializing numbers to text. Numbers are just numbers. – melpomene Aug 20 '18 at 05:39
  • 3
    Possible duplicate of [How to convert a hexadecimal string to a binary string in C](https://stackoverflow.com/q/8551383/608639) – jww Aug 20 '18 at 06:03
  • How do you _have the dest MAC address_ - as a string literal, or a string variable? – Armali Aug 20 '18 at 08:06

0 Answers0