pythonrosrospy

How is rosparam calculating the of leading-zero integers?


Could someone explain how ROS's rosparam command converts input and output values?
Specifically, I am surprised by the following set of commands caused by leading zeros:

$ rosparam set mytest 00111
$ rosparam get mytest
73

This isn't the conversion from binary, so what is happening here?


Solution

  • This is actually a bash feature, which ROS inherits when using the command-line interface. From the arithmetic evaluation section of the bash manual:

    Constants with a leading 0 are interpreted as octal numbers.

    You could reproduce this behavior without involving ROS at all:

    $ echo $((00111))
    73 #  73 = 64 + 8 + 1
    

    If you want to convert your number to decimal instead of octal, strip the leading zeroes before converting your value to an integer (see this SO answer )

    $ echo $((10#00111))
    111