LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to manipulate bits?

Q1.

BIP-4 checksum: is computed by xor'ing all the bytes in the packet together and then xor'ing the left nibble of the result with the right nibble of the result. 

 

unsigned char calcBIP4( unsigned char* data ) {
int i;
unsigned char bip8=(data[0]& 0x0f) ^ data[1] ^ data[2] ^ data[3];
unsigned char bip4=((bip8 & 0xf0) >>4) ^ (bip8 & 0x0f);
return bip4;

 

 

I have xor'ed all the bytes and get a U8 integer. how can I xor the left part with the right part? 

I tried to use 'split number', but for a U8, the high half is 0, and the low half is the same 8-bit number.

 

 

Q2.

assume I get a 4-bit checksum,  how to combine the checksum with 0001 to get a U8?

 

 

0 Kudos
Message 1 of 8
(4,421 Views)

Hi cantata,

 

what's the problem in using the very same function in LabVIEW as you would do in C?

 

check.png

 

Your Q2 is not defined very well, so I took the 2nd easiest approach…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(4,413 Views)

thank you very much!

 

for the 2nd question, I want to combine the checksum with 0001(write=1) to get a byte. for example, checksum=1111, then the byte=11110001.

could you tell me what is the 'RIQ' function called?

0 Kudos
Message 3 of 8
(4,404 Views)

Hi cantata,

 

for your Q2 explanation: the solution is shown above…

 

The function is found in the basic numerics function palette - just look for it! 😄

As a sidenote: by now you should have learned how to use SNIPPETS - they are explained in the LabVIEW help too…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 8
(4,397 Views)

In answer to the question "how to manipulate bits?" I was tempted to write, build up their hopes, feed them lies and pretend to be their friend.

 

But the answers given already are also good.

Message 5 of 8
(4,389 Views)

@cantata2014 wrote:

thank you very much!

 

for the 2nd question, I want to combine the checksum with 0001(write=1) to get a byte. for example, checksum=1111, then the byte=11110001.

could you tell me what is the 'RIQ' function called?


You just use the Shift function and then OR the result with 0b0001.


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
Message 6 of 8
(4,363 Views)

In Q1, why are you AND'ing data[0] with 0x0f? What is the purpose of this?

0 Kudos
Message 7 of 8
(4,024 Views)

Hi abuts,

 

when you answer to an old thread you should always use nicknames instead of  just "you" when you want to ask a specific participant ona specific problem. Or you need to link to the message you are talking about!

 

ANDing data usually is used to mask certain bits - to make sure all other bits are cleared…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 8
(4,020 Views)