terça-feira, 17 de setembro de 2013

How To Convert Hex to Decimals Using Bash

When you're troubleshooting Check Point kernel tables (by using 'fw tab') sometimes the -f parameter is not available to format the output, usually from hex to decimal format. Which makes your life very difficult if you're already addicted to the -f flag.

So if you're not familiar or willing to convert in your head hex to decimal. Or you don't want to open the Windows calculator in the Programmer's view or even don't have that available, bash can help you out. You can easily convert from hex to decimal and the other way aroung using the printf command. See below:

By using the %x the output of 254 is 'fe' which is the equivalent in hex.

The %d does the opposite, converting from hex to decimal.

Note that in this case you need to provide the 0x before the hex value. Also note that there is a ton of ways of achieving the same result. This is just one of them and that happens to work in any Secure Platform, Gaia or Linux deployment with Check Point.

Nenhum comentário:

Postar um comentário