Smarts ASL: How do you convert a hexadecimal string to an IP address in ASL?
search cancel

Smarts ASL: How do you convert a hexadecimal string to an IP address in ASL?

book

Article ID: 303892

calendar_today

Updated On:

Products

VMware

Issue/Introduction

Symptoms:


How do you convert a hexadecimal string to an IP address in Smarts ASL?

Trying to use the hexToIP method(operation) to convert a hexadecimal string to an IP address in ASL, but it seems to only work for the Availability Manager product.

Environment

VMware Smart Assurance - SMARTS

Cause

Availability Manager is the only Smarts product that can use the hexToIP method(operation).

Resolution

The following sample code shows how a hexadecimal string can be converted to an IP address in Smarts ASL:
//Break the hexadecimal string into two character pieces:
my_input = "0A011903";

START {
input = my_input;
ip : HEX_IP
} do {
print(ip);
stop();
}

HEX_IP {
o1 : READ_HEX_BYTE
o2 : READ_HEX_BYTE
o3 : READ_HEX_BYTE
o4 : READ_HEX_BYTE
} do {
return o1 . "." . o2 . "." . o3 . "." . o4;
}

// To read only 2 hex chars, we need to use 2 '1 character' matches
READ_HEX_BYTE {
c : rep(char, 2)
} do {
h = MY_HEX(c);
return h;
}

// We then essentially interpret those two characters as a hex string
// (the integer equivalent is what gets saved)
MY_HEX(x) {
input = x;
i : hex
} do {
return i;
}


OUTPUT:
10.1.25.3