Николай Елесин Николай Елесин - 2 months ago 22
Bash Question

Convert signed int number to unsigned whith shell script

I need to convert signed int32 number to unsigned using shell script

for example :

convert Input : -256
Expected output: 4294967040

Answer

this can help you;

#!/bin/bash
input=$1
if [[ $input -lt "0" ]]; then
    output=$((4294967296+$input))
else
    output=$input
fi
echo $output


#signed int32;
#–2,147,483,648 to 2,147,483,647
#unsigned int32
#0 to 4,294,967,295