From: Eric Blossom Date: Mon, 10 May 2010 21:31:15 +0000 (-0700) Subject: Add gru.hexshort to deal with short hex constants X-Git-Url: https://git.gag.com/?p=debian%2Fgnuradio;a=commitdiff_plain;h=1fc7c57f778a9f05ded1d216247242ee13632d03 Add gru.hexshort to deal with short hex constants --- diff --git a/gnuradio-core/src/python/gnuradio/gruimpl/hexint.py b/gnuradio-core/src/python/gnuradio/gruimpl/hexint.py index 8d46e819..f2808c44 100644 --- a/gnuradio-core/src/python/gnuradio/gruimpl/hexint.py +++ b/gnuradio-core/src/python/gnuradio/gruimpl/hexint.py @@ -30,3 +30,15 @@ def hexint(mask): if mask >= 2**31: return int(mask-2**32) return mask + +def hexshort(mask): + """ + Convert unsigned masks into signed shorts. + + This allows us to use hex constants like 0x8000 when talking to + our hardware and not get screwed by them getting treated as python + longs. + """ + if mask >= 2**15: + return int(mask-2**16) + return mask