ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

14 bit twos complement

Hi,

 

I have this data which is in the format of 16 bit. Now i need to convert it to a 14bit(0-13) twos complement. bit 14 and 15 will be some flag clear status. The data will be in 14 bit 2s complement HEX.

 

For eg. 0x0001 = 1 LSB, 0x0000 = 0 LSB and 0x3FFF = -1 LSB.

 

How can i implement this? Please advise. Thank you.

0 Kudos
Message 1 of 7
(6,324 Views)

Hi,

 

I assume in 14Bits:

0x1FFF is the maximal positive value.

0x3FFF is -1

Is right for you ?

 

May be a way:

try all your operations in 16bits,

At the end, compare if > 0x7FFF  (or if 16bits sign bit is set),

if true, make a right shift register of 2bits. This will convert your value in 14Bits digit.

if false, make a logical AND with 0x1FFF.

 

Best regards

Nicolas

0 Kudos
Message 2 of 7
(6,309 Views)

see attached file

0 Kudos
Message 3 of 7
(6,269 Views)

Hi Kate,

 

Is it possible to change I16 to a DBL? What are the things that i need to change? This is because i will have floating numbers.

0 Kudos
Message 4 of 7
(6,245 Views)

Hi nferry,

 

you are right, the MSB of the 14bits will be the sign. No wonder i don't get the correct result because i looked at it the wrong way. I manage to get the desired result already. Thank you.

0 Kudos
Message 5 of 7
(6,240 Views)

Hi all,

 

problem solved. Because i need to scale to by 0.05 first. for e.g. my reading is 10.55, then i need to scale by 0.05 which gives me 211 which will not have the floating number problem. Thank you to everyone!

0 Kudos
Message 6 of 7
(6,231 Views)

Hi all,

 

I am trying to do a separate part on read via RS232 so i tried one of the solution in this forum for the read part. I found that in the data that i am sending in the string, there is a 16bits 0 that is infront of each data. May i know if this is correct in rs232 communication or that i have done things wrongly in my attached vi. Please advise. Thank you.

0 Kudos
Message 7 of 7
(6,205 Views)