I'm trying to understand this code 100% but I'm not completely clear, especially because of the printf %02X
:
MAC_ADDRESS="AF:BA:44:2A:8F:3C"
# Se que sacamos un dijito a la derecha de la posicion '13' con ${MAC_ADDRESS:13:1}
printf %02X $((0x${MAC_ADDRESS:13:1} + 1))
#output:
10
I know that addition of hexadecimal numbers is being allowed, but I don't know what allows it or the purpose of it %02X
as the first argument to the command printf
.
# Algo raro es que al querer sumar "1 + D" me da un resultado erroneo, pues el resultado real deberia ser "0E"
printf %02X $((0x1+D))
#output:
01
Let's go by parts. Let's divide everything that happens for
printf
into three parts:Therefore you will have
printf %02X $((0xF+1))
, which in hexa is 10Regarding your doubt when doing
$((0x1+D))
, you are adding the letter D to 0x1 (hexadecimal).Maybe you wanted to do the following
$((0xD+1))
I hope it helps you, greetings!