{"id":334025,"date":"2022-06-03T15:00:54","date_gmt":"2022-06-03T15:00:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=334025"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=334025","title":{"rendered":"<span>JavaScript: \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u043e \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u0445 \u0438 \u0447\u0438\u0441\u043b\u0430\u0445 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/vn\/tg\/pz\/vntgpzpgemeytutve-gevcpoq0e.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/vn\/tg\/pz\/vntgpzpgemeytutve-gevcpoq0e.jpeg\" data-blurred=\"true\"\/>  <\/p>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f!<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0441 \u0432\u0430\u043c\u0438 \u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0438\u0442\u0430\u043c\u0438 \u0432 <code>JavaScript<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 (floating point numbers).<\/p>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u043d\u043e\u0441\u0438\u0442, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c, \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440 \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0443\u0433\u043b\u0443\u0431\u043b\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 <code>JavaScript<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u044b \u0438\u043c\u0435\u0435\u0442\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0435\u043d\u0438\u044f, \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%94%D0%B2%D0%BE%D0%B8%D1%87%D0%BD%D0%B0%D1%8F_%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0_%D1%81%D1%87%D0%B8%D1%81%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F\">\u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/a> \u0438 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u0445. \u041e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0445\u043e\u0440\u043e\u0448\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"https:\/\/learn.javascript.ru\/bitwise-operators\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 (\u0434\u043b\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044f \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443 \u043a \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/www.typescriptlang.org\/\">TypeScript<\/a>):<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ https:\/\/stackoverflow.com\/questions\/9939760\/how-do-i-convert-an-integer-to-binary-in-javascript const log = (n: number): void => {   console.log((n >>> 0).toString(2)) }<\/code><\/pre>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0437 <a href=\"https:\/\/github.com\/trekhleb\/javascript-algorithms\/tree\/master\/src\/algorithms\/math\/bits\">\u044d\u0442\u043e\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-polucheniya-bita\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0438\u0442\u0430<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">const getBit = (n: number, bitPosition\/* \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 0 *\/: number): number => (n >> bitPosition) &amp; 1  console.log(getBit(2, 1)) \/\/ 1<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0431\u0438\u0442 \u0432 \u043d\u0443\u043b\u0435\u0432\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e. \u0417\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>&amp;<\/code> \u0441 <code>1<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a <code>0001<\/code> \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044e \u0438\u0437 \u0447\u0438\u0441\u043b\u0430 \u0432\u0441\u0435\u0445 \u0431\u0438\u0442\u043e\u0432, \u043a\u0440\u043e\u043c\u0435 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e. \u0415\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0439\u0441\u044f \u0431\u0438\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>1<\/code>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f <code>1<\/code>, \u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f <code>0<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-ustanovki-bita\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0431\u0438\u0442\u0430<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">const setBit = (n: number, bitPosition: number): number => n | (1 &lt;&lt; bitPosition)  log(2)            \/\/ 10 log(setBit(2, 0)) \/\/ 11<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c <code>1<\/code> \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0442\u043e\u0432, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432 <code>bitPosition<\/code>, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 <code>0010<\/code>. \u0417\u0430\u0442\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>|<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0431\u0438\u0442 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>1<\/code>, \u043d\u043e \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u0442\u044b \u0447\u0438\u0441\u043b\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-ochistki-bita\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0431\u0438\u0442\u0430<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">function clearBit(n: number, bitPosition: number): number {   const mask = ~(1 &lt;&lt; bitPosition)    return n &amp; mask }  log(5)              \/\/ 101 log(clearBit(5, 0)) \/\/ 100<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c <code>1<\/code> \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0442\u043e\u0432, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432 <code>bitPosition<\/code>, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 <code>0010<\/code>. \u0417\u0430\u0442\u0435\u043c \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c \u0431\u0438\u0442\u044b \u043d\u0430 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u0435), \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 <code>1101<\/code>. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>&amp;<\/code> \u043d\u0430\u0434 \u043e\u0431\u043e\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0431\u0438\u0442\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-obnovleniya-bita\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0438\u0442\u0430<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">function updateBit(n: number, bitPosition: number, bitValue\/* 0 \u0438\u043b\u0438 1 *\/: number): number {   const normalized = bitValue ? 1 : 0   const mask = ~(1 &lt;&lt; bitPosition)   return (n &amp; mask) | (normalized &lt;&lt; bitPosition) }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <code>clearBit<\/code> \u0438 <code>setBit<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-opredeleniya-chetnosti-chisla\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u0430<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">const isEven = (n: number): number => (n &amp; 1) === 0  \/\/ 100 console.log(isEven(4)) \/\/ true \/\/ 101 console.log(isEven(5)) \/\/ false  \/\/ \u0438\u043b\u0438 const isOddOrEven = (n: number): string => (n &amp; 1 ? '\u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0435' : '\u0447\u0435\u0442\u043d\u043e\u0435') console.log(isOddOrEven(4)) \/\/ \u0447\u0435\u0442\u043d\u043e\u0435 console.log(isOddOrEven(5)) \/\/ \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0435<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0435\u0441\u044c \u0444\u043e\u043a\u0443\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u0440\u0430\u0439\u043d\u0438\u043c \u043f\u0440\u0430\u0432\u044b\u043c \u0431\u0438\u0442\u043e\u043c \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>1<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-opredeleniya-polozhitelnosti-chisla\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u0430<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">function isPositive(n: number): number {   if (n === 0) return false    return ((n >> 31) &amp; 1) === 0 }  console.log(isPositive(1))  \/\/ true console.log(isPositive(0))  \/\/ false console.log(isPositive(-1)) \/\/ false<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0440\u0430\u0439\u043d\u0438\u043c \u043b\u0435\u0432\u044b\u043c (<em>\u0441\u0442\u0430\u0440\u0448\u0438\u043c<\/em>) \u0431\u0438\u0442\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>0<\/code>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0434\u043b\u044f <code>+0<\/code> (\u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e <code>0<\/code>) \u0438 <code>-0<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f <code>false<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-umnozheniya-chisla-na-2\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 2<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">const multiplyByTwo = (n: number): number => n &lt;&lt; 1  log(5)                        \/\/ 0101 -> 0 + 2^2 + 0 + 2^0 (\u0441\u043c. \u043d\u0438\u0436\u0435) log(multiplyByTwo(5))         \/\/ 1010 -> 2^3 + 0 + 2^1 + 0 console.log(multiplyByTwo(5)) \/\/ 10<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0432\u0441\u0435 \u0431\u0438\u0442\u044b \u0447\u0438\u0441\u043b\u0430 \u0432\u043b\u0435\u0432\u043e \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 (\u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0447\u0438\u0441\u043b\u0430 <code>2<\/code>) \u0443\u043c\u043d\u043e\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 <code>2<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0441\u0430\u043c\u043e \u0447\u0438\u0441\u043b\u043e \u0442\u0430\u043a\u0436\u0435 \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <code>2<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-deleniya-chisla-na-2\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u043d\u0430 2<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">const divideByTwo = (n: number): number => n >> 1  log(4)                      \/\/ 100 -> 2^2 + 0 + 0 log(divideByTwo(4))         \/\/ 010 -> 0 + 0 + 2^1 console.log(divideByTwo(4)) \/\/ 2<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0432\u0441\u0435 \u0431\u0438\u0442\u044b \u0447\u0438\u0441\u043b\u0430 \u0432\u043f\u0440\u0430\u0432\u043e \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 (\u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0447\u0438\u0441\u043b\u0430 <code>2<\/code>) \u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043d\u0430 <code>2<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0441\u0430\u043c\u043e \u0447\u0438\u0441\u043b\u043e \u0442\u0430\u043a\u0436\u0435 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <code>2<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-smeny-znaka-chisla\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043c\u0435\u043d\u044b \u0437\u043d\u0430\u043a\u0430 \u0447\u0438\u0441\u043b\u0430<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">const switchSign = (n: number): number => ~n + 1  log(2)                     \/\/ 10 log(switchSign(2))         \/\/ -10 console.log(switchSign(2)) \/\/ -2<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0431\u0438\u0442\u044b \u0447\u0438\u0441\u043b\u0430 \u0438 \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u043d\u0438\u043c <code>1<\/code>. \u0414\u0430\u043d\u043d\u0430\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%94%D0%BE%D0%BF%D0%BE%D0%BB%D0%BD%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9_%D0%BA%D0%BE%D0%B4\">&#171;\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c&#187; \u0438\u043b\u0438 &#171;\u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u043e \u0434\u0432\u0443\u0445&#187;<\/a> (two&#8217;s complement).<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-opredeleniya-kolichestva-ustanovlennyh-bitov\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0431\u0438\u0442\u043e\u0432<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">function countSetBits(n: number): number {   let count = 0    while (number) {     \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0431\u0438\u0442 \u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443     count += number &amp; 1      \/\/ \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u043d\u0430 1 \u0431\u0438\u0442 \u0432\u043f\u0440\u0430\u0432\u043e \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0438\u0442\u043e\u0432     number >>>= 1   }    return count }  log(5)                        \/\/ 101 console.log(countSetBits(5))  \/\/ 2<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0437\u0434\u0435\u0441\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0432\u043f\u0440\u0430\u0432\u043e \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0431\u0438\u0442\u0443. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 <code>&amp;<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u0438\u0431\u043e <code>1<\/code>, \u043b\u0438\u0431\u043e <code>0<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-opredeleniya-kolichestva-bitov\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0431\u0438\u0442\u043e\u0432<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">function countBits(n: number): number {   let count = 0    while (1 &lt;&lt; count &lt;= n) {     count += 1   }    return count }  log(5)                    \/\/ 101 console.log(countBits(5)) \/\/ 3<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u043c <code>1<\/code> \u043d\u0430 \u043e\u0434\u0438\u043d \u0431\u0438\u0442 \u0432\u043b\u0435\u0432\u043e \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u0441\u0442\u0430\u043b\u043e \u043b\u0438 &#171;\u0441\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0435&#187; \u0447\u0438\u0441\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u043c\u0443. \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0430\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u043e <code>5<\/code>, <code>1<\/code> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c <code>4<\/code> \u0440\u0430\u0437\u0430.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-opredeleniya-togo-yavlyaetsya-li-chislo-stepenyu-chisla-2\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e \u0447\u0438\u0441\u043b\u0430 2<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">const isPowerOfTwo = (n: number): number => (n &amp; (n - 1)) === 0  console.log(isPowerOfTwo(4)) \/\/ true console.log(isPowerOfTwo(5)) \/\/ false<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e <code>n<\/code> \u2014 \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e \u0447\u0438\u0441\u043b\u0430 <code>2<\/code> (2, 4, 8, 16 \u0438 \u0442.\u0434.). \u0422\u043e\u0433\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <code>&amp;<\/code>, \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u043d\u0430\u044f \u043a <code>n<\/code> \u0438 <code>n - 1<\/code>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>0<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">4 &amp; (4 - 1) = 100 &amp; 011 = 000 -> \u0447\u0438\u0441\u043b\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e \u0447\u0438\u0441\u043b\u0430 2 10 &amp; (10 - 9) = 1010 &amp; 1001 = 1000 -> \u0447\u0438\u0441\u043b\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e \u0447\u0438\u0441\u043b\u0430 2<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"funkciya-umnozheniya-2-chisel-so-znakami\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f 2 \u0447\u0438\u0441\u0435\u043b \u0441\u043e \u0437\u043d\u0430\u043a\u0430\u043c\u0438<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/**  * \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c `a` \u0438\u043b\u0438 `b`, \u0438\u043b\u0438 \u043e\u0431\u043e\u0438\u0445 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0435\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f `0`:  * multiplySigned(a, b) === 0  *  * \u0415\u0441\u043b\u0438 `b` - \u0447\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e:  * multiplySigned(a, b) === multiplySigned(2 * a, b \/ 2)  *  * \u0415\u0441\u043b\u0438 `b` - \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e:  * multiplySigned(a, b) === multiplySigned(2 * a, (b - 1) \/ 2) + a  *  * \u0415\u0441\u043b\u0438 `b` - \u043d\u0435\u0447\u0435\u0442\u043d\u043e\u0435 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e:  * multiplySigned(a, b) === multiplySigned(2 * a, (b + 1) \/ 2) - a  *  * \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c: O(log b)  *\/ function multiplySigned(a: number, b: number): number {   if (b === 0 || a === 0) return 0    const multiplyByOddPositive = () =>     multiplySigned(multiplyByTwo(a), divideByTwo(b - 1)) + a   const multiplyByOddNegative = () =>     multiplySigned(multiplyByTwo(a), divideByTwo(b + 1)) - a    const multiplyByEven = () => multiplySigned(multiplyByTwo(a), divideByTwo(b))   const multiplyByOdd = () =>     isPositive(b) ? multiplyByOddPositive() : multiplyByOddNegative()    return isEven(b) ? multiplyByEven() : multiplyByOdd() }  console.log(multiplySigned(2, -4)) \/\/ -8<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>a * b<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>0<\/code>: \u043a\u043e\u0433\u0434\u0430 <code>a<\/code> \u0438\u043b\u0438 <code>b<\/code>, \u0438\u043b\u0438 <code>a<\/code> \u0438 <code>b<\/code> \u0440\u0430\u0432\u043d\u044b <code>0<\/code>;<\/li>\n<li><code>2a * (b\/2)<\/code>: \u043a\u043e\u0433\u0434\u0430 <code>b<\/code> \u2014 \u044d\u0442\u043e \u0447\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e;<\/li>\n<li><code>2a * (b-1)\/2 + a<\/code>: \u043a\u043e\u0433\u0434\u0430 <code>b<\/code> \u2014 \u044d\u0442\u043e \u0447\u0435\u0442\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e;<\/li>\n<li><code>2a * (b+1)\/2 - a<\/code>: \u043a\u043e\u0433\u0434\u0430 <code>b<\/code> \u2014 \u044d\u0442\u043e \u0447\u0435\u0442\u043d\u043e\u0435 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043e\u043f\u0435\u0440\u0430\u043d\u0434\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0432\u0434\u0432\u043e\u0435. \u041c\u044b \u0438\u043c\u0435\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c <code>O(log b)<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>b<\/code> \u2014 \u044d\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u043d\u0434, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0432 <code>2<\/code> \u0440\u0430\u0437\u0430 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"funkciya-umnozheniya-2-chisel-bez-znakov\">\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f 2 \u0447\u0438\u0441\u0435\u043b \u0431\u0435\u0437 \u0437\u043d\u0430\u043a\u043e\u0432<\/h2>\n<p>  <\/p>\n<pre><code class=\"javascript\">function multiplyUnsigned(x: number, y: number): number {   let result = 0    \/\/ \u043f\u0443\u0441\u0442\u044c `y` \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u0435\u043c `x`   let multiplier = y    \/\/ \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0431\u0438\u0442\u0430 \u043c\u043d\u043e\u0436\u0438\u0442\u0435\u043b\u044f   let bitIndex = 0    \/\/ \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0431\u0438\u0442\u044b `y`   while (multiplier !== 0) {     \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0431\u0438\u0442     if (multiplier &amp; 1) {       \/\/ \u0435\u0441\u043b\u0438 \u0431\u0438\u0442 \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d,       \/\/ \u0437\u043d\u0430\u0447\u0438\u0442, \u043d\u0443\u0436\u043d\u043e \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c `x` \u043d\u0430 \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u044d\u0442\u043e\u0433\u043e \u0431\u0438\u0442\u0430       \/\/ \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443       result += x &lt;&lt; bitIndex     }      bitIndex += 1     multiplier >>= 1   }    return result }  console.log(multiplyUnsigned(2, 4)) \/\/ 8<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043b\u0435\u0436\u0438\u0442 \u0438\u0434\u0435\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u0441\u0443\u043c\u043c\u0443 \u0441\u0442\u0435\u043f\u0435\u043d\u0435\u0439 \u0447\u0438\u0441\u043b\u0430 <code>2<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">19 = 2^4 + 2^1 + 2^0<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 <code>x<\/code> \u043d\u0430 <code>19<\/code> \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">x * 19 = x * 2^4 + x* 2^1 + x * 2^0<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 <code>x * 2^4<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0441\u0434\u0432\u0438\u0433 <code>x<\/code> \u043d\u0430 <code>4<\/code> \u0431\u0438\u0442\u0430 \u0432\u043b\u0435\u0432\u043e (<code>x &lt;&lt; 4<\/code>).<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0442\u0430\u043c\u0438 \u0447\u0438\u0441\u0435\u043b.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 <code>JavaScript<\/code>, \u0442\u043e, \u043a\u0440\u043e\u043c\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0435\u0442\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u0430, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c \u043e \u0434\u0432\u043e\u0439\u043d\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0435 <code>~<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0443 <code>Math.floor<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const n = ~~3.14 console.log(n) \/\/ 3<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0435 <code>~<\/code>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 <code>-1<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const arr = [3, 1, 2] arr.forEach((_, i) => {   if (~arr.indexOf(i)) {     console.log(`\u0412 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0435\u0441\u0442\u044c ${i}`)   } }) \/**  * \u0412 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0435\u0441\u0442\u044c 1  * \u0412 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0435\u0441\u0442\u044c 2  *\/<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 <code>JavaScript<\/code> \u043d\u0430 \u0442\u0430\u043a \u0443\u0436 \u0438 \u043c\u043d\u043e\u0433\u043e.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044f \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/UUID\">UUID<\/a> (<code>Node.js<\/code>):<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">const genUuid = () =>   ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(\/[018]\/g, (c) =>     (       c ^       (crypto.getRandomValues(new Uint8Array(1))[0] &amp; (15 >> (c \/ 4)))     ).toString(16)   )  console.log(genUuid()) \/\/ 7982fcfe-5721-4632-bede-6000885be57d<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 <code>HEX<\/code>:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">const getRandomHexColor = () =>   `#${((Math.random() * 0xffffff) &lt;&lt; 0).toString(16)}`  console.log(getRandomHexColor()) \/\/ #6ec80d<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0446\u0432\u0435\u0442\u0430 \u0438\u0437 <code>RGB<\/code> \u0432 <code>HEX<\/code>:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"javascript\">const RgbToHex = (r, g, b) =>   `#${((r &lt;&lt; 16) + (g &lt;&lt; 8) + b).toString(16).padStart(6, '0')}`  console.log(RgbToHex(255, 200, 55)) \/\/ #ffc837<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0437\u043d\u0430\u0435\u0442\u0435 \u0432\u044b? \u041f\u043e\u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439.<\/p>\n<p>  <\/p>\n<h2 id=\"chisla-dvoynoy-tochnosti-v-binarnom-formate\">\u0427\u0438\u0441\u043b\u0430 \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/trekhleb\/javascript-algorithms\/tree\/master\/src\/algorithms\/math\/binary-floating-point\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0412\u044b \u043a\u043e\u0433\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u043b\u0438\u0441\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u044b \u0445\u0440\u0430\u043d\u044f\u0442 \u0447\u0438\u0441\u043b\u0430 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>3.1416<\/code> (\u0447\u0438\u0441\u043b\u043e \u041f\u0438) \u0438\u043b\u0438 <code>9.109 \u00d7 10\u207b\u00b3\u00b9<\/code> (\u043c\u0430\u0441\u0441\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u0430 \u0432 \u043a\u0433), \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u0443\u043b\u0435\u0439 \u0438 \u0435\u0434\u0438\u043d\u0438\u0446 (\u0431\u0438\u0442\u043e\u0432)?<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0438\u0441\u043b\u043e\u043c <code>17<\/code>) \u0432\u0441\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c 16 \u0431\u0438\u0442 (2 \u0431\u0430\u0439\u0442\u0430) \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430. \u0412 16 \u0431\u0438\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <code>[0, 65535]<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(0000000000000000)\u2082 = (0)\u2081\u2080  (0000000000010001)\u2082 =     (1 \u00d7 2\u2074) +     (0 \u00d7 2\u00b3) +     (0 \u00d7 2\u00b2) +     (0 \u00d7 2\u00b9) +     (1 \u00d7 2\u2070) = (17)\u2081\u2080  (1111111111111111)\u2082 =     (1 \u00d7 2\u00b9\u2075) +     (1 \u00d7 2\u00b9\u2074) +     (1 \u00d7 2\u00b9\u00b3) +     (1 \u00d7 2\u00b9\u00b2) +     (1 \u00d7 2\u00b9\u00b9) +     (1 \u00d7 2\u00b9\u2070) +     (1 \u00d7 2\u2079) +     (1 \u00d7 2\u2078) +     (1 \u00d7 2\u2077) +     (1 \u00d7 2\u2076) +     (1 \u00d7 2\u2075) +     (1 \u00d7 2\u2074) +     (1 \u00d7 2\u00b3) +     (1 \u00d7 2\u00b2) +     (1 \u00d7 2\u00b9) +     (1 \u00d7 2\u2070) = (65535)\u2081\u2080<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0441\u043e \u0437\u043d\u0430\u043a\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u043e \u0434\u0432\u0443\u0445 \u0438 \u0441\u0434\u0432\u0438\u043d\u0443\u0442\u044c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d <code>[0, 65535]<\/code> \u0432 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 16 \u0431\u0438\u0442 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <code>[-32768, +32768]<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>-27.15625<\/code> (\u0447\u0438\u0441\u043b\u0430 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f).<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u044b \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u043f\u0435\u0440\u0432\u044b\u0435, \u043a\u0442\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443. \u0412 \u0434\u0430\u043b\u0435\u043a\u043e\u043c 1985 \u0433\u043e\u0434\u0443 \u0443\u043c\u043d\u044b\u0435 \u043b\u044e\u0434\u0438 \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u043b\u0438 \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 <a href=\"https:\/\/en.wikipedia.org\/wiki\/IEEE_754\">IEEE 754<\/a> \u0434\u043b\u044f \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 (\u0434\u0430\u043b\u0435\u0435 \u2014 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442).<\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f 16 \u0431\u0438\u0442 (\u0438\u043b\u0438 32, \u0438\u043b\u0438 64) \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 \u043e\u0442 0 \u0434\u043e 1.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0438\u0434\u0435\u044e, \u043b\u0435\u0436\u0430\u0449\u0443\u044e \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%AD%D0%BA%D1%81%D0%BF%D0%BE%D0%BD%D0%B5%D0%BD%D1%86%D0%B8%D0%B0%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F_%D0%B7%D0%B0%D0%BF%D0%B8%D1%81%D1%8C\">\u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438<\/a> (scientific notation) \u2014 \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0438\u043b\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c\u0438 (\u043e\u0431\u044b\u0447\u043d\u043e, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u0447\u0438\u0441\u0435\u043b) \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/re\/wi\/t0\/rewit03dhbxqa5xgydls20kjlrs.png\" data-src=\"https:\/\/habrastorage.org\/webt\/re\/wi\/t0\/rewit03dhbxqa5xgydls20kjlrs.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043e \u043d\u0430 3 \u0447\u0430\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>sign<\/code> \u2014 \u0437\u043d\u0430\u043a;<\/li>\n<li><code>fraction (significand)<\/code> \u2014 \u0444\u0440\u0430\u043a\u0446\u0438\u044f (\u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u0447\u0438\u0441\u043b\u0430, \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430) \u0447\u0438\u0441\u043b\u0430;<\/li>\n<li><code>exponent<\/code> \u2014 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f, \u043a\u0430\u043a \u0434\u0430\u043b\u0435\u043a\u043e \u0438 \u0432 \u043a\u0430\u043a\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u0430 \u0432\u043e \u0444\u0440\u0430\u043a\u0446\u0438\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0427\u0430\u0441\u0442\u044c <code>base<\/code> (\u043e\u0441\u043d\u043e\u0432\u0430, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f) \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c, \u0443\u0441\u043b\u043e\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043e \u0442\u043e\u043c, \u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f. \u041c\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u044b \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>2<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0445 16 \u0431\u0438\u0442 (\u0438\u043b\u0438 32, \u0438\u043b\u0438 64) \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0444\u0440\u0430\u043a\u0446\u0438\u0438 \u0447\u0438\u0441\u043b\u0430, \u0431\u0438\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u043a\u0430, \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u0444\u0440\u0430\u043a\u0446\u0438\u0438 \u043f\u043e-\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0431\u0438\u0442\u043e\u0432, \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u0440\u0430\u0441\u043f\u043e\u0440\u044f\u0436\u0435\u043d\u0438\u0438 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0424\u043e\u0440\u043c\u0430\u0442<\/th>\n<th>\u041e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0442\u043e\u0432<\/th>\n<th>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0442\u043e\u0432 \u0434\u043b\u044f \u0437\u043d\u0430\u043a\u0430<\/th>\n<th>\u0414\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/th>\n<th>\u0414\u043b\u044f \u0444\u0440\u0430\u043a\u0446\u0438\u0438<\/th>\n<th>\u041e\u0441\u043d\u043e\u0432\u0430<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u041f\u043e\u043b\u043e\u0432\u0438\u043d\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/td>\n<td>16<\/td>\n<td>1<\/td>\n<td>5<\/td>\n<td>10<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0434\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/td>\n<td>32<\/td>\n<td>1<\/td>\n<td>8<\/td>\n<td>23<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>\u0414\u0432\u043e\u0439\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/td>\n<td>64<\/td>\n<td>1<\/td>\n<td>11<\/td>\n<td>52<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0442\u043e\u0432 \u0434\u043b\u044f \u0444\u0440\u0430\u043a\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043c\u0435\u0441\u0442\u043e <code>16<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435\u0433\u043e <code>10<\/code>). \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u043e \u0444\u0440\u0430\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0438\u0439 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0447\u0438\u0441\u0435\u043b (\u0441 \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0442\u0435\u0440\u0435\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438). \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 \u043d\u0430\u0441 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0447\u0438\u0441\u0435\u043b \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442\u0441\u044f. \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 0 \u0438 1 (\u0437\u0430 \u0441\u0447\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b).<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f 32-\u0431\u0438\u0442\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>2\u00b3\u00b9 \u2212 1 = 2,147,483,647<\/code>, \u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f 32-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0441 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435\u043c 2 \u043f\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>\u2248 3.4028235 \u00d7 10\u00b3\u2078<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <a href=\"https:\/\/en.wikipedia.org\/wiki\/Exponent_bias\">\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/a> (exponent bias) \u2014 \u0432\u044b\u0447\u0438\u0442\u0430\u043d\u0438\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f (bias) \u0438\u0437 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438\u043c\u0435\u0435\u0442 <code>5<\/code> \u0431\u0438\u0442, \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <code>[0, 31]<\/code> (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435). \u041d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u044b\u0447\u0442\u0435\u043c \u0438\u0437 \u043d\u0435\u0435 <code>15<\/code>, \u0442\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a <code>[-15, 16]<\/code>. \u0427\u0438\u0441\u043b\u043e <code>15<\/code> \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\u043c \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">exponent_bias = 2 ^ (k \u2212 1) \u2212 1  k - \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0442\u043e\u0432 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u043d\u0438\u0436\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0432 \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f 16-\u0431\u0438\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043d\u043e \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 32 \u0438 64-\u0431\u0438\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/30\/97\/lz\/3097lzp_jlqcd35fout8d7uyzqa.png\" data-src=\"https:\/\/habrastorage.org\/webt\/30\/97\/lz\/3097lzp_jlqcd35fout8d7uyzqa.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u0412 <a href=\"https:\/\/trekhleb.dev\/blog\/2021\/binary-floating-point\/\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0424\u043e\u0440\u043c\u0430\u0442<\/th>\n<th>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/th>\n<th>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/th>\n<th>\u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d<\/th>\n<th>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u041f\u043e\u043b\u043e\u0432\u0438\u043d\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/td>\n<td>-14<\/td>\n<td>+15<\/td>\n<td>\u00b165,504<\/td>\n<td>6.10 \u00d7 10\u207b\u2075<\/td>\n<\/tr>\n<tr>\n<td>\u041e\u0434\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/td>\n<td>-126<\/td>\n<td>+127<\/td>\n<td>\u00b13.4028235 \u00d7 10\u00b3\u2078<\/td>\n<td>1.18 \u00d7 10\u207b\u00b3\u2078<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043b\u0438\u0448\u044c \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0430\u0439\u043d\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0441\u043e\u0431\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435. \u0420\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u043e \u0442\u0430\u043a\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445, \u043a\u0430\u043a <code>-0<\/code>, <code>-Infinity<\/code>, <code>+Infinity<\/code> \u0438 <code>NaN<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430<\/strong><\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/trekhleb\/javascript-algorithms\/blob\/master\/src\/algorithms\/math\/binary-floating-point\/bitsToFloat.js\">bitsToFloat<\/a> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0438\u0442\u043e\u0432 \u0432 \u0447\u0438\u0441\u043b\u043e \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439;<\/li>\n<li><a href=\"https:\/\/github.com\/trekhleb\/javascript-algorithms\/blob\/master\/src\/algorithms\/math\/binary-floating-point\/floatAsBinaryString.js\">floatAsBinaryString<\/a> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443.<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/strong><\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/indepth.dev\/posts\/1139\/here-is-what-you-need-to-know-about-javascripts-number-type\">\u0412\u043e\u0442, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043e \u0447\u0438\u0441\u043b\u0430\u0445 \u0432 JavaScript<\/a><\/li>\n<li><a href=\"https:\/\/float.exposed\/0x44bf9400\">Float Exposed<\/a><\/li>\n<li><a href=\"https:\/\/bartaz.github.io\/ieee754-visualization\/\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f IEEE 754<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u044d\u0442\u043e \u0432\u0441\u0435, \u0447\u0435\u043c \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0435. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u044b \u043d\u0430\u0448\u043b\u0438 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0447\u0442\u043e-\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0438 \u043d\u0435 \u0437\u0440\u044f \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  <\/p>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 happy coding!<\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<p><a href=\"https:\/\/cloud.timeweb.com\/vds-promo-10-rub?utm_source=habr&amp;utm_medium=banner&amp;utm_campaign=vds-promo-10-rub\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/co\/e2\/kh\/coe2kha8u8_pypip-2k3wk3ppa0.png\" data-src=\"https:\/\/habrastorage.org\/webt\/co\/e2\/kh\/coe2kha8u8_pypip-2k3wk3ppa0.png\"\/><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/timeweb\/blog\/669394\/\"> https:\/\/habr.com\/ru\/company\/timeweb\/blog\/669394\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/vn\/tg\/pz\/vntgpzpgemeytutve-gevcpoq0e.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/vn\/tg\/pz\/vntgpzpgemeytutve-gevcpoq0e.jpeg\" data-blurred=\"true\"\/>  <\/p>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u0440\u0443\u0437\u044c\u044f!<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0441 \u0432\u0430\u043c\u0438 \u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0438\u0442\u0430\u043c\u0438 \u0432 <code>JavaScript<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 (floating point numbers).<\/p>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u043d\u043e\u0441\u0438\u0442, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c, \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440 \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0443\u0433\u043b\u0443\u0431\u043b\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 <code>JavaScript<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u044b \u0438\u043c\u0435\u0435\u0442\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0435\u043d\u0438\u044f, \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%94%D0%B2%D0%BE%D0%B8%D1%87%D0%BD%D0%B0%D1%8F_%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0_%D1%81%D1%87%D0%B8%D1%81%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F\">\u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/a> \u0438 \u043f\u043e\u0431\u0438\u0442\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u0445. \u041e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0445\u043e\u0440\u043e\u0448\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"https:\/\/learn.javascript.ru\/bitwise-operators\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 (\u0434\u043b\u044f \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044f \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443 \u043a \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/www.typescriptlang.org\/\">TypeScript<\/a>):<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ https:\/\/stackoverflow.com\/questions\/9939760\/how-do-i-convert-an-integer-to-binary-in-javascript const log = (n: number): void => {   console.log((n >>> 0).toString(2)) }<\/code><\/pre>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-334025","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=334025"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334025\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}