Linux shell different binary data conversion (binary, octal, hexadecimal, base64)

  
 

The shell can not call the third party command, indicating different hex data. The following representations are summarized here. The default value of a shell script is handled by a decimal number, unless the number begins with a special notation or prefix. It can represent other hex type values. For example, starting with 0 is octal. Starting with 0x is a hexadecimal number. Using BASE#NUMBER this form can represent other hexadecimal .BASE values: 2-64.


How to use:

  • Other decimals are converted to decimal

    Hexadecimal to decimal:

    [chengmo@centos5 ~]$ ((num =0123));[chengmo@centos5 ~]$ echo $num;83

    [chengmo@centos5 ~]$ ((num=8#123));[chengmo@centos5 ~]$ echo $num ; 83

    ((expression)), (()) can be any data expression. If you add in the previous: & rdquo; $ & rdquo; you can read the calculation results.

    Hexadecimal to decimal:

    [chengmo@centos5 ~]$ ((num=0xff)); [chengmo@centos5 ~]$ echo $num; 255[chengmo@centos5 ~]$ ((num=16#ff));[chengmo@centos5 ~]$ echo $num; 255

    base-32 to decimal:

    [chengmo@centos5 ~]$ ((num=32#ffff));[chengmo@centos5 ~]$ echo $num; 507375

    base64 to decimal:

    [chengmo@centos5 ~]$ ((num=64 #abc_)); [chengmo@centos5 ~]$ echo $num; 2667327

    Binary to Decimal

    [chengmo@centos5 ~]$ ((num=2#11111111)); [ ,null,null,3],Chengmo@centos5 ~]$ echo $num;255



  • decimal to other decimal

    decimal to octal

    This is used to: bc external command completion. The bc command format is converted to: echo "obase=ade; value"

  • Copyright © Windows knowledge All Rights Reserved