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: 

get number of bits in integer without converting to string first

Is there a way to do this without converting to a string first to use the string length function? I feel this would be inefficient because type cast makes a data copy (but maybe I'm splitting hairs). I don't want to convert to boolean array and use array size either (inefficient). This is running in a tight loop on RT and that's why I'm concerned. I am trying to preinitialize an array with an index for each bit, and if for some reason I change my code from 16 to 32 bit integers, I don't want to have to go change everywhere I used a constant of 16. 

0 Kudos
Message 1 of 13
(2,758 Views)

I know it might start a flame war but whats wrong with a Global?


"Should be" isn't "Is" -Jay
Message 2 of 13
(2,749 Views)

@JÞB wrote:

I know it might start a flame war but whats wrong with a Global?


Actually, I considered this! No flames from me. The only drawback here is it still needs to be updated, not calculated programmatically. Although the update would only be in one place, it's still nice if it can be calculated in code, making a transition seemless. I'm not against it, I'm just looking for different possible solutions for my own knowledge more than anything. The chance of thi changing in this specific project is slim to none.

0 Kudos
Message 3 of 13
(2,739 Views)

@JÞB wrote:

I know it might start a flame war but whats wrong with a Global?


Smiley SurprisedJeff is suggesting a global variable?

 

Actually, I'm in complete agreement.  A global variable that is read only is a very simple, effective, efficient (even processing), and race condition free way to set constants that could change on you.


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 13
(2,737 Views)

@for(imstuck) wrote:

This is running in a tight loop on RT and that's why I'm concerned.


Why is the "calculation" done inside of the loop?  Can you do it before the loop starts?  I don't know your code, so it could very well be that there is nothing outside of the loop loop that could tell you the data type.


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 5 of 13
(2,733 Views)

@crossrulz wrote:

@for(imstuck) wrote:

This is running in a tight loop on RT and that's why I'm concerned.


Why is the "calculation" done inside of the loop?  Can you do it before the loop starts?  I don't know your code, so it could very well be that there is nothing outside of the loop loop that could tell you the data type.


It is in the loop because it can change based on how many milliseconds of data I'm reading. depending on the test I'm running. In standard operation I read 10 ms of 48 I16s of buffered data (480 elements) which results in an array of 7680 (480*16). Certain other tests I just grab a snippet of 2 ms of data, so now the array is 96*16. 

 

I suppose I could make it loop invariant code by caculating the max possible array size for any situation outside the loop, then trim it down accordingly.

0 Kudos
Message 6 of 13
(2,721 Views)

You can probably use this to set your Global

!1.png

DRAT

I mean

Example_VI_BD.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 13
(2,704 Views)

@JÞB wrote:

You can probably use this to set your Global

!1.png

DRAT

I mean

Example_VI_BD.png


One problem with that option is that it uses scripting.  Therefore it can only be used in the development environment.


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 8 of 13
(2,673 Views)

Tim,

Its read only in runtime.  Reading is all thats neededSmiley Very Happy

 

I assume Greg can create the case structure to convert rep to number of bits and write to a Global Variable.  (without Rube-Goldberging it TOO much):smileyvery-happy:


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 13
(2,663 Views)

@JÞB wrote:

Tim,

Its read only in runtime.  Reading is all thats neededSmiley Very Happy

 

I assume Greg can create the case structure to convert rep to number of bits and write to a Global Variable.  (without Rube-Goldberging it TOO much):smileyvery-happy:


Ok.  The blueish property node got to me.  I see now that it is read-only during the run-time.


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 10 of 13
(2,629 Views)