You don't really need bit operations to do that. For example:
awk '{val = $1;
c = val%65536; val = (val-c)/65536;
b = val%65536; val = (val-b)/65536;
a = val%65536;
print a, b, c}'
However, awk values are not 64-bit integers; they are doubles, which only have 53 bits of precision. So that will only work if none of your numbers are greater than 9007199254740992 (253).
You might consider using a different tool, like bc
or python
. If you have GNU bc
available (which is possible, even on a BSD system), the following very similar program should work:
bc <(echo 'define s(val) {
c = val%65536; val = (val-c)/65536
b = val%65536; val = (val-b)/65536
a = val%65536;
print a," ",b," ",c,"\n";
}
while(1){v=read(); if (v==0) break; v=s(v);}') \
< datafile
Note well: the bc
read function does not check for end of file, so you need to put some kind of explicit terminator in. I used 0
in the above script, but that might be a valid input in your case. You might want to change it to -1
or some other special value. Whatever, make sure that your datafile is actually terminated with that value.