logoalt Hacker News

Retr0idyesterday at 4:26 PM1 replyview on HN

Also, endian-correct code is usually semantically clearer. For example, if you're reading network-ordered bytes into an int, an unconditional endian swap (which will produce correct results on LE systems but not BE) is less clear than invoking a "network bytes to u32" helper.


Replies

namibjyesterday at 7:02 PM

u32::from_be_bytes

u32::from_le_bytes

u32::from_ne_bytes the n stands for native