From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

The Daily CLAD

Community Browser
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: CLAD2017 - Fundamentals - You are looking a bit shifty

SercoSteveB
Active Participant

Which of the following generated the data shown in Boolean Array Out?

 

Boolean Array Out.png

a)

Boolean Array Out Answer 1.png

b)

Boolean Array Out Answer 2.png

c)

Boolean Array Out Answer 3.png

d)

Boolean Array Out Answer 4.png

Comments
Bcortes
NI Employee (retired)

C is the right answer

Bcortes
NI Employee (retired)

Here is the explanation:Daily CLAD 8-Feb-2018.png

LeBaTai09
Member

Hello everybody, I'm a fresher, for the wrong answers for the next questions, could anybody explain for me a reason ? Please and thanks so much. I need to understand deeply, not only the true answers. 

AUlikyan_ANEL
Member

C

Baltur
Member

C)

 

@TEO99:

For starters look up all the functions if you are not familiar with them. Also I recommend dragging the snippets in LabVIEW and then use probes to check what is going on.

The boolean array to number function will transform the array to number. The default representation is U32 and in Daily CLAD you can expect the default unless stated otherwise.

The logical shift will shift the bits of the numbers like Bcortes showed. The lower input is the number to shift and the upper input how far to shift. If the upper input is positive, the bits will move to the left meaning in direction from least significant to most significant bit. If the upper input is negative the direction is reversed. Important note: Bits that are shifted 'outside' will NOT roll over to the other side, instead there will be padding with 0s.

The important nodes are the compound arithmetics which work bitwise: ^ = AND and v = OR.

 

About the wrong answers:

A) You have "Original number OR Shifted number" meaning that TRUE bits of the original number will always be set plus the bit of the shifted number. And U32 representation means there is no danger that the shifting will turn the number negative.  This means in all iterations the "Greater than 0" function will output true and the output array of the FOR-loop will not be identical to the original.

B) The "Shifted number OR 1" will guarantee that at least the least signifant bit will always be set plus the TRUE bits of the shifted number. This leads again to the output array of the FOR-loop being all TRUE and not identical to original.

D) A bit more complex. Here you have bitwise AND of the shifted and the orignal number. In first iteration the shift by 0 and orignal are identical -> Output 101001 -> Greater than 0 -> TRUE.

Second iteration the shifted number is of by 1 bit. 1010010 AND 0101001 = 0000000 -> Not greater than 0 -> False. If you go through all iteration the output of the FOR loop will be T, F, T, T, F, T. This will again be not identical to the orignal and the Boolean Array Out will be T,T,T, F, T, T and not all TRUE.

 

LeBaTai09
Member

@Baltur thank you. 

crossrulz
Knight of NI

C


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Ganesh_anbu
Member

here, I can't able to understand the working of a logical shift. can someone make me clear with this logical shift.???

SercoSteveB
Active Participant

Hi Ganesh_anbu

Check out the Logical Shift LabVIEW 2017 Help.  In summary, the lower input terminal (x) value is shifted to the left the number of bits defined by the value of the upper input terminal (y). output = x << y.  It is a good idea to think about your values in binary representation when dealing with Logical Shift. 

NOTE: You can shift to the right by specifying a y value of less than 0.

 

Examples. 

If x = 1 (B'1') and y = 1, output = 2 (B'10')

If x = 1 (B'1') and y = 2, output = 4 (B'100')

If x = 2 (B'10') and y = 1, output = 4 (B'100')

If x = 2 (B'10') and y = -1, output = 1 (B'1')

 

Hope this helps

 

Steve

Matt-A.
Member

c

Ellie90
Member

c

SPK91
Member

C

Priya16
Member

C

mini09
Active Participant

Agreed C

A.Bernau
Member

C

rak84
Member

c

istan0227
Member

C