#[bash] echo-ing integers with more than 63 bits

4 messages · Page 1 of 1 (latest)

somber cairn
#

Since bash overflows after 2^63-1 I have done quite a bit of research already and many people on StackOverflow have advised others to use the command bc in the form of var=$( bc <<< "$number" ) however, this doesn't seem to work in the output. It works fine for integers up to 62 bits but it still overflows when I echo "$var". I am using the online IDE from exercism. Is there any other way around this?

jaunty shadow
#

printf can help for another bit by forcing it to an unsigned int, eg for Grains

gaunt locust
#

At a bash prompt, enter help printf, man 1 printf and man 3 printf

jaunty shadow
#

Note help printf and man printf document different (though similar) commands. You want the former command.