# LabVIEW

cancel
Showing results 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

Message 1 of 8
(633 Views)

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

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

Message 2 of 8
(609 Views)

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

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
Message 3 of 8
(599 Views)

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

@AeroSoul wrote:

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

That won't do it.

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

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

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

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))

Message 5 of 8
(572 Views)

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

@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))

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 🙂

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
(551 Views)

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

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

"Should be" isn't "Is" -Jay
Message 7 of 8
(525 Views)

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

@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 😄

Message 8 of 8
(446 Views)