ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

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
(2,849 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
(2,825 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
(2,815 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
(2,801 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
(2,788 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
(2,767 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
(2,741 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
(2,662 Views)