XQN number format

Q Numbers Format
An XQN format number is an 1+X+N bit twos complement binary number; a sign bit
followed by X integer bits followed by an N bit mantissa (fraction). XQN format can be used
to express numbers in the range (-2X) to (2X - 2(-N)). An equivalent notation using the
System Generator Fix format, defined as Fixword_length_fractional_length, would be
Fix(1+X+N)_N.
A number using Q15 format is equivalent to a number using Fix16_15 representation, and a
number in 1Q15 format is equivalent to a number using Fix17_15 representation.
Table 3-8 and Table 3-9 contain examples of XQN Format Numbers.
Table 3-8: 1QN Format Data: Example of a 1Q7 (or Fix9_7) Format Number
(Sign)
Bit 8 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
+1 0 1 0 0 0 0 0 0 0
-1 1 1 0 0 0 0 0 0 0
+Pi/4 0 0 1 1 0 0 1 0 0
-Pi/4 1 1 0 0 1 1 0 1 1
Fractional Bits
Table 3-9: 2QN Format Phase: Example of a 2Q6 (or Fix9_6) Format Number
(Sign)
Bit 8 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 BIt 0
+1 0 0 1 0 0 0 0 0 0
-1 1 1 1 0 0 0 0 0 0
+Pi 0 1 1 0 0 1 0 0 1
-Pi 1 0 0 1 1 0 1 1 1

 

十进制小数转换成二进制小数采用"乘2取整,顺序排列"法。具体做法是:用2乘十进制小数,可以得到积,将积的整数部分取出,再用2乘余下的小数部分,又 得到一个积,再将积的整数部分取出,如此进行,直到积中的整数部分为零,或者整数部分为1,此时0或1为二进制的最后一位。或者达到所要求的精度为止。 
  然后把取出的整数部分按顺序排列起来,先取的整数作为二进制小数的高位有效位,后取的整数作为低位有效位。  

 十进制小数转二进制 
  如:0.625=(0.101)B 
  0.625*2=1.25======取出整数部分1 
  0.25*2=0.5========取出整数部分0 
  0.5*2=1==========取出整数部分1 

  再如:0.7=(0.1 0110 0110...)B 
  0.7*2=1.4========取出整数部分1 
  0.4*2=0.8========取出整数部分0 
  0.8*2=1.6========取出整数部分1 
  0.6*2=1.2========取出整数部分1 
  0.2*2=0.4========取出整数部分0  
  0.4*2=0.8========取出整数部分0 
  0.8*2=1.6========取出整数部分1 
  0.6*2=1.2========取出整数部分1 
  0.2*2=0.4========取出整数部分0

参考:http://whudongyang.iteye.com/blog/1208120

补码为反码加1.

posted @ 2017-08-25 10:44  喵喵小学僧  阅读(363)  评论(0编辑  收藏  举报