- Convert other hexadecimal values to hexadecimal values
Octal 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 "$" is added, the calculation result can be read.
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
Convert base64 to decimal:
[Chengmo @ centos5 ~] $ (Num = 64 # ABC _));
[Chengmo @ centos5 ~] $ Echo $ num;
2667327
Convert binary to decimal
[Chengmo @ centos5 ~] $ (Num = 2 #11111111 ));
[Chengmo @ centos5 ~] $ Echo $ num;
255
- Convert decimal to other hexadecimal
Decimal to octal
Here, the BC external command is used. BC command format conversion: Echo "obase = hexadecimal; Value" | BC
[Chengmo @ centos5 ~] $ Echo "obase = 8; 01234567" | BC
4553207
Binary, hexadecimal, and base64 are converted to decimal.
[Chengmo @ centos5 ~] $ Echo "obase = 64; 123456" | BC
30 09 00
Shell, built-in various hexadecimal representation methods are very simple. Remember base # number. Remember to use the () symbol when assigning values. You cannot use the = sign directly. = No value type. By default, the backend is changed to a string. For example:
[Chengmo @ centos5 ~] $ Num = 0123;
[Chengmo @ centos5 ~] $ Echo $ num;
0123
It is meaningless to start with 0.
You can use the operator "let" to perform the () operation.
[Chengmo @ centos5 ~] $ Let num = 0123;
[Chengmo @ centos5 ~] $ Echo $ num;
83