コード例 #1
0
 def test_xstr2float(self):
     # All numbers will be 32_16
     sign_bit = 32
     frac_bits = 16
     # Positive, integer
     xstr = '00040000'
     self.assertEqual(4, utility.xstr2float(xstr, frac_bits, sign_bit))
     # Positive, fractional
     xstr = '0004c000'
     self.assertEqual(4.75, utility.xstr2float(xstr, frac_bits, sign_bit))
     # Negative, integer
     xstr = 'fffc0000'
     self.assertEqual(-4, utility.xstr2float(xstr, frac_bits, sign_bit))
     # Negative, fractional
     xstr = 'fffb4000'
     self.assertEqual(-4.75, utility.xstr2float(xstr, frac_bits, sign_bit))
     # Zero
     xstr = '0'
     self.assertEqual(0, utility.xstr2float(xstr, frac_bits, sign_bit))
コード例 #2
0
ファイル: utils.py プロジェクト: nrao/guppi-controller
 def plot(values, frac_bits=0, sign_bit=None):
     toplot = []
     for v in values:
         toplot.append(xstr2float(v, frac_bits, sign_bit))
     print
     print 'plotting ...'
     print 'x\ty'
     print '----------'
     for i in range(len(toplot)):
         if toplot[i] != 0:
             print i, '\t', toplot[i]
     print '----------'
     pylab.plot(toplot)
     pylab.show()