Add gru.hexshort to deal with short hex constants
authorEric Blossom <eb@comsec.com>
Mon, 10 May 2010 21:31:15 +0000 (14:31 -0700)
committerEric Blossom <eb@comsec.com>
Mon, 10 May 2010 21:31:15 +0000 (14:31 -0700)
gnuradio-core/src/python/gnuradio/gruimpl/hexint.py

index 8d46e8192f90924ab72368c45f5611047f5d6388..f2808c44890a3188029edc352f32ca8b7e05df5b 100644 (file)
@@ -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