- Endian Conversion Functions | Qt Core (original) (raw)
The header provides functions to convert between little and big endian representations of numbers. More...
Function Documentation
template T qFromBigEndian(const void *src)
Reads a big-endian number from memory location src and returns the number in the host byte order representation. On CPU architectures where the host byte order is little-endian (such as x86) this will swap the byte order; otherwise it will just read from src.
Note: Template type T
can either be a quint16, qint16, quint32, qint32, quint64, or qint64. Other types of integers, e.g., qlong, are not applicable.
Note: Since Qt 5.7, the type of the src parameter is a void pointer.
There are no data alignment constraints for src.
See also qFromLittleEndian(), qToBigEndian(), and qToLittleEndian().
[constexpr]
template T qFromBigEndian(T src)
This is an overloaded function.
Converts src from big-endian byte order and returns the number in host byte order representation of that number. On CPU architectures where the host byte order is little-endian (such as x86) this will return src with the byte order swapped; otherwise it will return src unmodified.
template void qFromBigEndian(const void *src, qsizetype count, void *dest)
Reads count big-endian numbers from memory location src and stores them in the host byte order representation at dest. On CPU architectures where the host byte order is little-endian (such as x86) this will swap the byte order; otherwise it will just perform a memcpy
from src to dest.
Note: Template type T
can either be a quint16, qint16, quint32, qint32, quint64, or qint64. Other types of integers, e.g., qlong, are not applicable.
There are no data alignment constraints for src. However, dest is expected to be naturally aligned for type T
.
If src and dest can be the same pointer, this function will perform an in-place swap (if necessary). If they are not the same, the memory regions must not overlap.
See also qFromLittleEndian(), qToBigEndian(), and qToLittleEndian().
template T qFromLittleEndian(const void *src)
Reads a little-endian number from memory location src and returns the number in the host byte order representation. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will swap the byte order; otherwise it will just read from src.
Note: Template type T
can either be a quint16, qint16, quint32, qint32, quint64, or qint64. Other types of integers, e.g., qlong, are not applicable.
Note: Since Qt 5.7, the type of the src parameter is a void pointer.
There are no data alignment constraints for src.
See also qFromBigEndian(), qToBigEndian(), and qToLittleEndian().
[constexpr]
template T qFromLittleEndian(T src)
This is an overloaded function.
Converts src from little-endian byte order and returns the number in host byte order representation of that number. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will return src with the byte order swapped; otherwise it will return src unmodified.
template void qFromLittleEndian(const void *src, qsizetype count, void *dest)
Reads count little-endian numbers from memory location src and stores them in the host byte order representation at dest. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will swap the byte order; otherwise it will just perform a memcpy
from src to dest.
Note: Template type T
can either be a quint16, qint16, quint32, qint32, quint64, or qint64. Other types of integers, e.g., qlong, are not applicable.
There are no data alignment constraints for src. However, dest is expected to be naturally aligned for type T
.
If src and dest can be the same pointer, this function will perform an in-place swap (if necessary). If they are not the same, the memory regions must not overlap.
See also qToBigEndian() and qToLittleEndian().
template void qToBigEndian(T src, void *dest)
Writes the number src with template type T
to the memory location at dest in big-endian byte order.
Note: Template type T
can either be a quint16, qint16, quint32, qint32, quint64, or qint64. Other types of integers, e.g., qlong, are not applicable.
There are no data alignment constraints for dest.
Note: Since Qt 5.7, the type of the dest parameter is a void pointer.
See also qFromBigEndian(), qFromLittleEndian(), and qToLittleEndian().
[constexpr]
template T qToBigEndian(T src)
This is an overloaded function.
Converts src from host byte order and returns the number in big-endian byte order representation of that number. On CPU architectures where the host byte order is little-endian (such as x86) this will return src with the byte order swapped; otherwise it will return src unmodified.
template void qToBigEndian(const void *src, qsizetype count, void *dest)
Reads count numbers from memory location src in the host byte order and stores them in big-endian representation at dest. On CPU architectures where the host byte order is little-endian (such as x86) this will swap the byte order; otherwise it will just perform a memcpy
from src to dest.
Note: Template type T
can either be a quint16, qint16, quint32, qint32, quint64, or qint64. Other types of integers, e.g., qlong, are not applicable.
There are no data alignment constraints for dest. However, src is expected to be naturally aligned for type T
.
If src and dest can be the same pointer, this function will perform an in-place swap (if necessary). If they are not the same, the memory regions must not overlap.
See also qFromLittleEndian(), qToBigEndian(), and qToLittleEndian().
template void qToLittleEndian(T src, void *dest)
Writes the number src with template type T
to the memory location at dest in little-endian byte order.
Note: Template type T
can either be a quint16, qint16, quint32, qint32, quint64, or qint64. Other types of integers, e.g., qlong, are not applicable.
There are no data alignment constraints for dest.
Note: Since Qt 5.7, the type of the dest parameter is a void pointer.
See also qFromBigEndian(), qFromLittleEndian(), and qToBigEndian().
[constexpr]
template T qToLittleEndian(T src)
This is an overloaded function.
Converts src from host byte order and returns the number in little-endian byte order representation of that number. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will return src with the byte order swapped; otherwise it will return src unmodified.
template void qToLittleEndian(const void *src, qsizetype count, void *dest)
Reads count numbers from memory location src in the host byte order and stores them in little-endian representation at dest. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will swap the byte order; otherwise it will just perform a memcpy
from src to dest.
Note: Template type T
can either be a quint16, qint16, quint32, qint32, quint64, or qint64. Other types of integers, e.g., qlong, are not applicable.
There are no data alignment constraints for dest. However, src is expected to be naturally aligned for type T
.
If src and dest can be the same pointer, this function will perform an in-place swap (if necessary). If they are not the same, the memory regions must not overlap.
See also qFromLittleEndian(), qToBigEndian(), and qToLittleEndian().