![]() |
In C++ programming, there’s a new addition in C++20 called std::endian. It’s a helper that makes dealing with the way computers store data in memory much simpler. In this article, we will discuss the std::endian and how to use it in C++ program. What is Endianness?Before we look at the std::endian, let’s quickly chat about endianness. Endianness is the way computers store data that cannot be stored in a single byte like numbers. There are two types: little-endian and big-endian. Little-endian stores the least significant digit at the lower memory address and big-endian stores the most significant digits at the lower memory address. std::endian in C++The definition of the std::endian is C++ is:
It is defined inside <bit> header file. The std::endian enum has three members,
Here
ExampleC++
Output This computer is little-endian!
This code uses std::endian to figure out if the computer is little-endian or big-endian and prints it out. Why Endianess Matters?The knowledge of endianess helps us to makes our code more adaptable to different computers. If our program deals with saving and reading data in a binary format (like an encrypted code), knowledge of endianess can save us from problems when our code moves to a different system. |
Reffered: https://www.geeksforgeeks.org
C++ |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |