How to define a petabyte constant in VB.NET

1 Answer

0 votes
Imports System

Module PetabyteExample

    '
    ' In VB.NET, the largest unsigned integer type is ULong (64‑bit).
    ' Its maximum value is about 1.84 × 10^19.
    '
    ' A petabyte fits comfortably:
    '
    '   1 PiB = 2^50  = 1,125,899,906,842,624 bytes
    '   1 PB  = 10^15 = 1,000,000,000,000,000 bytes
    '
    ' So both can be stored safely in a ULong.
    '

    ' Binary petabyte (pebibyte), using a bit shift.
    ' 1UL << 50 = 2^50 bytes.
    Public Const PETABYTE_PIB As ULong = 1UL << 50

    ' Decimal petabyte (SI petabyte), using a readable numeric literal.
    ' VB.NET allows underscores for digit grouping.
    Public Const PETABYTE_PB As ULong = 1_000_000_000_000_000UL

    Sub Main()
        Console.WriteLine("1 PiB = " & PETABYTE_PIB & " bytes")
        Console.WriteLine("1 PB  = " & PETABYTE_PB & " bytes")
    End Sub

End Module



' run:
'
' 1 PiB = 1125899906842624 bytes
' 1 PB  = 1000000000000000 bytes
'

 



answered May 2 by avibootz
...