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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

binary bit operation

Solved!
Go to solution

Hi,

 

I just met a problem with 9-digits in binary bit operation.

Long time ago, I manipulated some binary and remembered that the first digit could be considered as significant or other specical meaning.

 

Though I guess the solution as the attachment, I would like to know the right technique in binary operation.

1) How can I replace the FOR loop with a simple bit operator?

 

2) I am trying to use U16 (16 bit) to adopt all  nine digits but how to remove the first digit or some digits in sequence as a final data? (In my code, I just substract a number from the calculated number.)

for example, (1)101000111 ->101000111 or (11)01000111 ->01000111

 

3) In other curious question, the lower three digits (111) is fixed in my application.

How can I separate or add the digit in calculation for simplicity?

for example, 110100(high)+(or some operation)111(lower)=110100111

 

labmaster.

code: LabVIEW 2014.

 

Download All
0 Kudos
Message 1 of 7
(5,961 Views)

Hi master,

 

1) (1)101000111 ->101000111 or (11)01000111 ->01000111

1xyzb AND 0111b = 0xyzb

 

2) 110100(high)+(or some operation)111(lower)=110100111

xyzb * 1000b + 0111b = xyz111b

 

("b" marks binary numbers)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(5,943 Views)

Thanks!. I forgot digital operation at all.

I revised my posting. Can you review my question again?

0 Kudos
Message 3 of 7
(5,938 Views)
Solution
Accepted by topic author labmaster

@labmaster wrote:

2) I am trying to use U16 (16 bit) to adopt all  nine digits but how to remove the first digit or some digits in sequence as a final data? (In my code, I just substract a number from the calculated number.)

for example, (1)101000111 ->101000111 or (11)01000111 ->01000111


I typically use an AND to mask off the bits I do not care about.

 


@labmaster wrote:

3) In other curious question, the lower three digits (111) is fixed in my application.

How can I separate or add the digit in calculation for simplicity?

for example, 110100(high)+(or some operation)111(lower)=110100111


That is typically done with some interesting masking (with the AND) or setting of bits (with the OR) and the Logical Shift.


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
0 Kudos
Message 4 of 7
(5,926 Views)

Hi master,

 

instead of adding a number 45 times you can also multiply that number by 45 before adding:

check.png

Hint: Always make the radix visible when you use non-decimal numbers!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 7
(5,923 Views)

Thanks for your additional comments.

 

if x=3 (decimal), y=00010 (binary)

if x=64, y=11111

 

There is an offset (-1 in decimal) for simple equation.

The problem to me is how to treat the most significant digit.

How can you set up a formula using the bit shift or boolean operation without any numerical operator?

 

labmaster.

 

 

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

Hi master,

 

The problem to me is how to treat the most significant digit.

What exactly is the problem?

Do you have specifications/requirement on how to handle the MSB? Then apply them!

(If needed you apply your rules to each mathematical operation!)

 

How can you set up a formula using the bit shift or boolean operation without any numerical operator?

Why do you want to have mathematical operations without using mathematical operators?

 

It seems to me you are talking about "saturated arithmetic" (see Wikipedia). Can you describe the algorithm you want to program?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 7
(5,894 Views)