How to define an exabyte constant in Kotlin

1 Answer

0 votes
/*
    Kotlin's Long type is a signed 64‑bit integer.
    Maximum value: 9_223_372_036_854_775_807  (~9.22 × 10^18)

    Exabyte sizes:

        1 EiB = 2^60  = 1_152_921_504_606_846_976 bytes
        1 EB  = 10^18 = 1_000_000_000_000_000_000 bytes

    Both values fit safely inside a Long.
*/

// Binary exabyte (exbibyte), using a bit shift.
// 1L shl 60 = 2^60 bytes.
const val EXABYTE_EIB: Long = 1L shl 60

// Decimal exabyte (SI), using a readable numeric literal.
const val EXABYTE_EB: Long = 1_000_000_000_000_000_000L

fun main() {
    println("1 EiB = $EXABYTE_EIB bytes")
    println("1 EB  = $EXABYTE_EB bytes")
}


/*
run:

1 EiB = 1152921504606846976 bytes
1 EB  = 1000000000000000000 bytes

*/

 



answered May 3 by avibootz
...