本文簡要介紹rust語言中 isize.to_ne_bytes
的用法。
用法
pub const fn to_ne_bytes(self) -> [u8; 8]
將此整數的內存表示形式返回為本機字節順序的字節數組。
由於使用了目標平台的本機字節順序,因此可移植代碼應酌情使用 to_be_bytes
或 to_le_bytes
。
注意:該函數根據目標指針大小返回長度為 2、4 或 8 字節的數組。
例子
let bytes = 0x1234567890123456isize.to_ne_bytes();
assert_eq!(
bytes,
if cfg!(target_endian = "big") {
[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]
} else {
[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]
}
);
相關用法
- Rust isize.to_le_bytes用法及代碼示例
- Rust isize.to_le用法及代碼示例
- Rust isize.to_be用法及代碼示例
- Rust isize.to_be_bytes用法及代碼示例
- Rust isize.trailing_zeros用法及代碼示例
- Rust isize.trailing_ones用法及代碼示例
- Rust isize.unstable_div_floor用法及代碼示例
- Rust isize.swap_bytes用法及代碼示例
- Rust isize.from_ne_bytes用法及代碼示例
- Rust isize.checked_pow用法及代碼示例
- Rust isize.wrapping_sub_unsigned用法及代碼示例
- Rust isize.from_le_bytes用法及代碼示例
- Rust isize.checked_log10用法及代碼示例
- Rust isize.pow用法及代碼示例
- Rust isize.checked_log2用法及代碼示例
- Rust isize.overflowing_div_euclid用法及代碼示例
- Rust isize.saturating_sub_unsigned用法及代碼示例
- Rust isize.saturating_neg用法及代碼示例
- Rust isize.saturating_abs用法及代碼示例
- Rust isize.checked_mul用法及代碼示例
- Rust isize.saturating_add_unsigned用法及代碼示例
- Rust isize.checked_neg用法及代碼示例
- Rust isize.unstable_div_ceil用法及代碼示例
- Rust isize.overflowing_sub用法及代碼示例
- Rust isize.is_negative用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 isize.to_ne_bytes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。