wiki/computing.endianness.html
2022-07-29 15:41:17 +00:00

17 lines
8.6 KiB
HTML

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Endianness</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
MathJax = {
tex: {
inlineMath: [ [&#x27;$&#x27;,&#x27;$&#x27;], [&#x27;\(&#x27;,&#x27;\)&#x27;] ],
displayMath: [ [&#x27;$$&#x27;,&#x27;$$&#x27;], [&#x27;[&#x27;,&#x27;]&#x27;] ]
},
options = {
processHtmlClass = &quot;math&quot;
}
}
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Endianness</h1><section class="post-metadata"><span>Date: <!-- -->2020-07-10 23:30:27 +08:00</span><span>Date modified: <!-- -->2021-05-19 17:37:14 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"></ol></nav><p>Endianness refers to how bits are read and this depends on the underlying hardware architecture.
</p><p>For example, given the following bit, 11010, this could be read as <span class="math math-inline">\(<!-- -->(1\times2^{0}) + (1\times2^{1}) + (0\times2^{2}) + (1\times2^{3}) + (0\times2^{4})<!-- -->\)</span> or <span class="math math-inline">\(<!-- -->11<!-- -->\)</span> with the first bit being the least significant also known as <strong>little-endian</strong>.
On the other hand, this could also be read as <span class="math math-inline">\(<!-- -->(0\times2^{0}) + (1\times2^{1}) + (0\times2^{2}) + (1\times2^{3}) + (1\times2^{4})<!-- -->\)</span> or <span class="math math-inline">\(<!-- -->26<!-- -->\)</span> with the last bit being the least significant which we refer to as <strong>big-endian</strong>.
</p><p>Endianness can have subtle effects on various things — e.g., using binary data formats like <a href="https://fits.gsfc.nasa.gov/">FITS</a> and <a href="https://www.hdfgroup.org/solutions/hdf5">HDF</a> — like having the wrong endianness.
</p><p>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&#x27;s little-endian — otherwise, it is big-endian.
If you have Python installed, you can simply use <a href="https://docs.python.org/3/library/sys.html#sys.byteorder"><code class="inline-code">sys.byteorder</code></a> (e.g., <code class="inline-code">python -c &#x27;import sys; print(sys.byteorder)</code>).
</p><section><h2>Backlinks</h2><ul><li><a href="/wiki/literature.reproducible-research-methodological-principles-for-transparent-science">Reproducible research: methodological principles for transparent science</a></li></ul></section></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"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},"page":"/[[...slug]]","query":{"slug":["computing.endianness"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html>