#endian #little-endian #big-endian

cpu-endian

cpu-endian 是一个可移植的crate,用于检测CPU的字节序。它检测CPU原生标量类型的排序方式;小端或大端,或其他(如PDP端序、混合端序、中间端序等。)

2个版本

0.1.1 2020年12月10日
0.1.0 2020年12月10日

#441 in 操作系统

LGPL-3.0-or-later OR Apache-2…

775KB
62

包含(WOFF字体,190KB)docs/FiraSans-Medium.woff,(WOFF字体,185KB)docs/FiraSans-Regular.woff,(WOFF字体,94KB)docs/SourceSerifPro-Bold.ttf.woff,(WOFF字体,89KB)docs/SourceSerifPro-Regular.ttf.woff,(WOFF字体,56KB)docs/SourceCodePro-Regular.woff,(WOFF字体,56KB)docs/SourceCodePro-Semibold.woff更多

cpu-endian

cpu-endian 是一个可移植的crate,用于检测CPU的字节序。

它检测CPU原生标量类型的排序方式;小端或大端,或其他(如PDP端序、混合端序、中间端序等。)

示例

use cpu_endian::{Endian, working};

// Takes first octet of 0x00ff: u16.
let v: u16 = 0x00ff;
let first_octet: u8 = unsafe {
    let ptr = &v as *const u16;
    let ptr = ptr as *const u8;
    *ptr
};

// If the byte-order is little-endian, the first octet should be 0xff, or if big-endian,
// it should be 0x00.
match working() {
    Endian::Little => assert_eq!(0xff, first_octet),
    Endian::Big => assert_eq!(0x00, first_octet),
    _ => {},
}

要求

如果CPU既不是 x86 也不是 x86_64 ,则需要C++编译器并具有c++20功能。


lib.rs:

cpu-endian

cpu-endian 是一个可移植的crate,用于检测CPU的字节序。

它检测CPU原生标量类型的排序方式;小端或大端,或其他(如PDP端序、混合端序、中间端序等。)

示例

use cpu_endian::{Endian, working};

// Takes first octet of 0x00ff: u16.
let v: u16 = 0x00ff;
let first_octet: u8 = unsafe {
    let ptr = &v as *const u16;
    let ptr = ptr as *const u8;
    *ptr
};

// If the byte-order is little-endian, the first octet should be 0xff, or if big-endian,
// it should be 0x00.
match working() {
    Endian::Little => assert_eq!(0xff, first_octet),
    Endian::Big => assert_eq!(0x00, first_octet),
    _ => {},
}

无运行时依赖