{"pageProps":{"metadata":{"date":"\"2020-07-10 23:30:27 +08:00\"","date_modified":"\"2021-05-19 17:37:14 +08:00\"","language":"en","source":""},"title":"Endianness","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Endianness refers to how bits are read and this depends on the underlying hardware architecture.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example, given the following bit, 11010, this could be read as "},{"type":"element","tagName":"span","properties":{"className":["math","math-inline"]},"children":[{"type":"text","value":"\\("},{"type":"text","value":"(1\\times2^{0}) + (1\\times2^{1}) + (0\\times2^{2}) + (1\\times2^{3}) + (0\\times2^{4})"},{"type":"text","value":"\\)"}]},{"type":"text","value":" or "},{"type":"element","tagName":"span","properties":{"className":["math","math-inline"]},"children":[{"type":"text","value":"\\("},{"type":"text","value":"11"},{"type":"text","value":"\\)"}]},{"type":"text","value":" with the first bit being the least significant also known as "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"little-endian"}]},{"type":"text","value":".\nOn the other hand, this could also be read as "},{"type":"element","tagName":"span","properties":{"className":["math","math-inline"]},"children":[{"type":"text","value":"\\("},{"type":"text","value":"(0\\times2^{0}) + (1\\times2^{1}) + (0\\times2^{2}) + (1\\times2^{3}) + (1\\times2^{4})"},{"type":"text","value":"\\)"}]},{"type":"text","value":" or "},{"type":"element","tagName":"span","properties":{"className":["math","math-inline"]},"children":[{"type":"text","value":"\\("},{"type":"text","value":"26"},{"type":"text","value":"\\)"}]},{"type":"text","value":" with the last bit being the least significant which we refer to as "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"big-endian"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Endianness can have subtle effects on various things — e.g., using binary data formats like "},{"type":"element","tagName":"a","properties":{"href":"https://fits.gsfc.nasa.gov/"},"children":[{"type":"text","value":"FITS"}]},{"type":"text","value":" and "},{"type":"element","tagName":"a","properties":{"href":"https://www.hdfgroup.org/solutions/hdf5"},"children":[{"type":"text","value":"HDF"}]},{"type":"text","value":" — like having the wrong endianness.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"To know the endianness of your machine, you can simply create a test number (preferably in binary) and check for the first few digits if it's little-endian — otherwise, it is big-endian.\nIf you have Python installed, you can simply use "},{"type":"element","tagName":"a","properties":{"href":"https://docs.python.org/3/library/sys.html#sys.byteorder"},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"sys.byteorder"}]}]},{"type":"text","value":" (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"python -c 'import sys; print(sys.byteorder)"}]},{"type":"text","value":").\n"}]}]},"backlinks":[{"path":"/literature.reproducible-research-methodological-principles-for-transparent-science","title":"Reproducible research: methodological principles for transparent science"}]},"__N_SSG":true}