0

When I type in the shell ->

$echo $(( 16#FF ))

The output is "255" which is the decimal conversion of the hexadecimal number "0xFF"

But when I try to convert the number "FF" to another base similarly:

$ echo $(( ffb5cd10#FF ))

I get the following error:

"bash: ffb5cd10#FF : syntax error: invalid arithmetic operator (error token is "#FF ")"
Share a link to this question
CC BY-SA 4.0
2
0

So the correct syntax of this command is $echo $ (('base'#number )) where base is actually the base of the number you have given to the shell and it will give you the decimal conversion. Here, FF is the number and 16 is the base and FF converts to 255..

Share a link to this answer
CC BY-SA 4.0
1
  • It looks like this only works for hexadecimal numbers which are less than or equal to decimal 9,999,999,999,999,999,999 (= 10,000,000,000,000,000,000 - 1 = 10 billion billion - 1). 484867784a5845516146550a base 16 to base 10 = 22370451988863230639950157066 = true and $ echo $((16#484867784a5845516146550a)) = 5357107972583871754 = false. echo $((16#550a)) = 21770 = true.
    – Rublacava
    1 min ago
0

I think your problem is here:

"(error token is "#FF ")"

you put a number in hex format and ask to return a hex again.

the sintax for this, (i think) can return the expected result if you ommit the base from the code, like this:

$ echo $(( ffb5cd10# ))

Share a link to this answer
CC BY-SA 4.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.