Code Monkey home page Code Monkey logo

128-bit-literals's Introduction

128-bit literals in C++11 and C++14

In C++, you can store 8-bit integers, 16-bit integers, 32-bit integers, and 64-bit integers:

int8_t alice;
int64_t bob;

GCC and Clang even have 128-bit integers:

__int128 carol;

You can store 128-bit integers, but you aren't allowed to write 128-bit integers:

__int128 dave = 18446744073709551616;
error: integer literal is too large to be represented in any integer type
__int128 dave = 18446744073709551616;
                ^

This library allows you to write 128-bit integers:

#include "suffix128.hpp"
__int128 emily = 18446744073709551616_128;

All you have to do is #include "suffix128.hpp" and end your integer with the suffix _128.


You can use the suffix _u128 for unsigned integers:

unsigned __int128 frank = 123456789012345678901234567890_u128;

128-bit integers you write this way are constants and they can be used as template parameters or enumerator initializers.

enum Bar { BAZ = 0_128 };

You can use C++14's single-quote digit separator:

__int128 gloria = 1'2'3'456'7_128;

You can also write them in hexadecimal or octal notation:

__int128 hector = 0xfeed'bad'beef'2'dad_128;
__int128 imelda = 0644_128;

You can even write 128-bit binary literals:

unsigned __int128 jules = 0b00000001000001100001010000111000100100010110001101000111100100110010101001011100110110011101001111101010110101111011011101111111_u128;

128-bit-literals's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.