NI Home > Community > NI Discussion Forums


Showing results for 
Search instead for 
Do you mean 
Posts: 12
Accepted Solution

how to subtract two (uint16)1D array of same size

I need to subtract two (uint16) 1D array of same size. with folowing output...

x - y = result(EXPECTED)

5 - 2 = 3

4 - 0 = 4

0 - 4 = 0

2 - 3 = 0


If difference is less than zero value should be zero. Right now, if I use numeric subtraction...i get .... 


x - y = result(OBSERVED)

5 - 2 = 3

4 - 0 = 4

0 - 4 = 4

2 - 3 = 1


Thank You 

Chosen by topic author rajxabc
Posts: 33

Re: how to subtract two (uint16)1D array of same size

[ Edited ]

Hello rajxabc,


I'm not sure why you expect unsigned integer math to produce a 0 in the scenario you show below.  The U16 will actually wrap past 0.




0 - 1 = 65535

0 - 2 = 65534

0 - 3 = 65533





If you want to change the standard behavior of unsigned integer math, you'll have to create a special algorithm to produce this, something like:




There's a number of ways you could accomplish this but at the end of the day, I'm not sure I would label any of them "expected".

Posts: 12

Re: how to subtract two (uint16)1D array of same size

Your soultion is correct. Perhaps i was asking wrong question because i am still not able to acomplish what i wanted to do.

Kindly see attached block diagram. 

incomming data is accumulated added values on each interval. (i dont have seperate access to new incomming values)

So, what i am trying to do is to , substract new array from last observed array .

for that i am using global array initialised with zero. is there a way to do that.

before i tried shift register, but on each loop my array was initialised to zeros.

Can you help me here . or i have to ask new question ?


I am accepting the previous answere.


Knight of NI
Posts: 11,736

Re: how to subtract two (uint16)1D array of same size

Hi raj,


do you see all the red dots in your VI?

Why do you have a "0" constant as DBL instead of using an integer datatype as shown before?

Why don't you use a feedback node instead of globals?


Attach the real VI...

Best regards,

CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome Smiley Wink
Posts: 12

Re: how to subtract two (uint16)1D array of same size

[ Edited ]

Hi GradW,


i tried to use feedback node, but it all got more confusing.

attached is vi file I am trying to modify for my need. I dont know LV at all.

The Idea is to save subtracted array as they come.


Array Xn - Xn-1 --> save to csv

Any suggestions would be helpfull. 

Thank you