Created
March 27, 2024 06:27
-
-
Save ardislu/1a7ff72fc38a70a4b4ac40933e67bc91 to your computer and use it in GitHub Desktop.
This is the minimum amount of JavaScript (74 characters) to detect the endianness of a platform.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The magic number 0xFEFF is selected for familiarity with the commonly-used | |
// byte-order mark (BOM) character (https://en.wikipedia.org/wiki/Byte_order_mark). | |
const isLE = new Uint8Array(new Uint16Array([0xFEFF]).buffer)[0] === 0xFF; | |
// Golfed (-12 characters; 62 total characters): | |
// const isLE=new Uint8Array(new Uint16Array([256]).buffer)[0]<1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment