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: 

Convert 1024 to 1KB like "%.2p" SI conversion

Hi

 

Is there a function or feature that will convert an integer or double value to an SI equivalent decimal string, but using 1024 as the divisor? 

 

I.e

2^10 = 1024 (K)

2^20 = 1048576 (M)

2^30 =  1073741824 (G)

Etc

 

In other words -

0 < N < 1024 = "N"

1024 < N < 1048576 = "<N/1024> K"

1048576 < N < 1073741824 = "<N/1048576> M"

ETC

 

I'd be surprised if such a function does not exist. Or am I being naive?

 

Thanks

0 Kudos
Message 1 of 8
(1,382 Views)

I don't know if it exists, but it's really not hard to do by yourself:

 

tokB.png

0 Kudos
Message 2 of 8
(1,358 Views)

Use an array of "",k,M,G,T and look up quotient of Log2(x),10 as the index.

Format "%f %sB" where f is Remainder log2(x), 10 and %s is the string from the Lookup table


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 8
(1,348 Views)

@AeroSoul wrote:

I don't know if it exists, but it's really not hard to do by yourself:

 

tokB.png


That won't do it.

This kind of works, but the result is funky if the input is < 1024.

fs.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 8
(1,334 Views)

This works for practically anything, but i don't really like how it handles the decimal points.

JPB's idea, but i couldn't get his to work with the Remainder Log2(x), 10, so i did x/(1024^(log2(x)/10))

tokB2.png

0 Kudos
Message 5 of 8
(1,321 Views)

@AeroSoul wrote:

This works for practically anything, but i don't really like how it handles the decimal points.

JPB's idea, but i couldn't get his to work with the Remainder Log2(x), 10, so i did x/(1024^(log2(x)/10))

tokB2.png


Well, that would be because I failed to describe the conversion correctly.  CERTAINLY this was a problem with trying to type from my phone and not a failure to properly think through the math 🙂

ToSciBytesJÞB.png

 

I don't understand why x is not a Unsigned Integer in AeroSoul's picture of a snippet Last I checked Bytes can't be negative or fractional.


"Should be" isn't "Is" -Jay
Message 6 of 8
(1,300 Views)

Minor mod to add coverage for Peta and Exa (Zetta and Yotta are ignored since a U64 0xFFFFFFFFFFFFFFFF is a mere16EB-1Byte.)  We need P and E to prevent indexing past the array size and making large numbers look small

ToSciBytesJÞBrevwE.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 8
(1,274 Views)

@JÞB wrote:

I don't understand why x is not a Unsigned Integer in AeroSoul's picture of a snippet Last I checked Bytes can't be negative or fractional.


Because right click--> create control on the log2(x) makes it a double 😄

0 Kudos
Message 8 of 8
(1,195 Views)