Skip to content

A byte utils class to handle bytes with literals.

License

Notifications You must be signed in to change notification settings

CodebyCR/ByteUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ByteUtils

A byte utils class to handle bytes with literals, for more expressive byte handling

  • smooth calculation between decimal and binary suffixes.
  • fast readable and concise code.
  • fitting to literal.
  • compertibal with big integer types.

Main intension:

    // Withot ByteUtils
    auto _2GiB = 2'147'483'648;
    auto _512MB = 512'000'000;
    auto result = _2GiB - _512MB;
    std::cout << "result: " << result << std::endl; // result: 1637483648

    /// With ByteUtils
    using namespace ByteUtils;
    auto result = 2_GiB - 512_MB;
    std::cout << "result: " << result << std::endl; // result: 1637483648

More examples:

    using namespace ByteUtils;
    auto zipFileSize = 2_GiB;
    std::cout << "zipFileSize: " << zipFileSize << std::endl;
    // zipFileSize: 2147483648

    auto zipFileSize2 = 2_GB;
    std::cout << "zipFileSize2: " << zipFileSize2 << std::endl;
    // zipFileSize2: 2000000000

    auto newSize = zipFileSize - 1024_MB;
    std::cout << "newSize: " << newSize << std::endl;
    // newSize: 1123483648

    auto newSize2 = newSize - 512_KiB;
    std::cout << "newSize2: " << newSize2 << std::endl;
    // newSize2: 1122959360

    auto newSize3 = newSize2 - 256_B;
    std::cout << "newSize3: " << newSize3 << std::endl;
    // newSize3: 1122959104

    std::cout << fit_to_Literal(newSize3) << std::endl;
    // 1 Gib

    std::cout << to_MiB_as_string(newSize3) << std::endl;
    // 1070 MiB

    std::cout << to_MB(newSize3) << std::endl;
    // 1122
    
    std::cout << to_KiB_as_string(7168) << std::endl;
    // 7 KiB

    std::cout << to_KB(1122957168) << std::endl;
    // 1122957

About

A byte utils class to handle bytes with literals.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages