Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bit shift

38 views
Skip to first unread message

Wai Au

unread,
Feb 2, 2012, 3:17:54 PM2/2/12
to
in 8.4, expr 38016 << 16 returns -1803550720. In 8.5, the same
expression returns 2491416576. Is there a way to get the negative
value in 8.5?

Wai Au

unread,
Feb 2, 2012, 3:48:28 PM2/2/12
to
ok, i got it. scan [expr 38016 << 16] %i returns the signed value.

Don Porter

unread,
Feb 7, 2012, 9:57:01 AM2/7/12
to
Beware. Neither that, nor your original command is portable to
64-bit systems.

--
| Don Porter Applied and Computational Mathematics Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Don Porter

unread,
Feb 7, 2012, 10:09:00 AM2/7/12
to

>>> in 8.4, expr 38016 << 16 returns -1803550720. In 8.5, the same
>>> expression returns 2491416576. Is there a way to get the negative
>>> value in 8.5?

Here's one portable answer:

% proc 32bit {val} {
binary scan [binary format i $val] i result
return $result
}
% 32bit [expr {38016 << 16}]
-1803550720
0 new messages