\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Arest (arest)} \pdfinfo{ /Title (cs29912.pdf) /Creator (Cheatography) /Author (Arest (arest)) /Subject (Трюки с битами Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{125900} \definecolor{LightBackground}{HTML}{F7F9F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Трюки с битами Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Arest (arest)} via \textcolor{DarkBackground}{\uline{cheatography.com/7517/cs/29912/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Arest (arest) \\ \uline{cheatography.com/arest} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 24th November, 2021.\\ Updated 24th November, 2021.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Целые}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Установка n\textasciicircum{}го\textasciicircum{} бита}} & `x | (1\textless{}\textless{}n)` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Выключение n\textasciicircum{}го\textasciicircum{} бита}} & `x \& \textasciitilde{}(1\textless{}\textless{}n)` \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{нверсия n\textasciicircum{}го\textasciicircum{} бита}} & `x \textasciicircum{} (1\textless{}\textless{}n)` \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} {\bf{Округление вниз}} & `n \textgreater{}\textgreater{} 0 \{\{nl\}\}5.7812 \textgreater{}\textgreater{} 0` //{\emph{ вернёт 5}} \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{Умножение на 2}} & 1`n \textless{}\textless{} 1;` \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} {\bf{Деление на 2}} & `n \textgreater{}\textgreater{} 1;` \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{Умножение на m\textasciicircum{}ую\textasciicircum{} степень двойки}} & `n \textless{}\textless{} m;` \tn % Row Count 18 (+ 4) % Row 7 \SetRowColor{white} {\bf{Деление на m\textasciicircum{}ую\textasciicircum{} степень двойки}} & `n \textgreater{}\textgreater{} m;` \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} {\bf{Проверка на чётность (кратность 2)}} & `(n \& 1) == 1;` \tn % Row Count 25 (+ 4) % Row 9 \SetRowColor{white} {\bf{Максимум из двух}} & `b \& ((a-b) \textgreater{}\textgreater{} 31) | a \& (\textasciitilde{}(a-b) \textgreater{}\textgreater{} 31);` \tn % Row Count 28 (+ 3) % Row 10 \SetRowColor{LightBackground} {\bf{Минимум из двух}} & `a \& ((a-b) \textgreater{}\textgreater{} 31) | b \& (\textasciitilde{}(a-b) \textgreater{}\textgreater{} 31);` \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Целые (cont)}} \tn % Row 11 \SetRowColor{LightBackground} {\bf{Проверка на \seqsplit{одинаковый} знак}} & `(x \textasciicircum{} y) \textgreater{}= 0;` \tn % Row Count 3 (+ 3) % Row 12 \SetRowColor{white} {\bf{Смена знака}} & `i = \textasciitilde{}i + 1;` {\emph{// or}} \{\{nl\}\}`i = (i \textasciicircum{} -1) + 1;` {\emph{// i = -i}} \tn % Row Count 6 (+ 3) % Row 13 \SetRowColor{LightBackground} {\bf{Вернёт 2\textasciicircum{}n\textasciicircum{}}} & `1 \textless{}\textless{} n;` \tn % Row Count 8 (+ 2) % Row 14 \SetRowColor{white} {\bf{Является ли число степенью 2}} & `n \textgreater{} 0 \&\& !(n \& (n - 1));` \tn % Row Count 11 (+ 3) % Row 15 \SetRowColor{LightBackground} {\bf{Остаток от деления на 2\textasciicircum{}n\textasciicircum{} на m}} & `m \& ((1 \textless{}\textless{} n) - 1);` \tn % Row Count 14 (+ 3) % Row 16 \SetRowColor{white} {\bf{Среднее \{\{nl\}\}арифметическое}} & `(x + y) \textgreater{}\textgreater{} 1; \{\{nl\}\}((x \textasciicircum{} y) \textgreater{}\textgreater{} 1) + (x \& y);` \tn % Row Count 17 (+ 3) % Row 17 \SetRowColor{LightBackground} {\bf{Получить m\textasciicircum{}ый\textasciicircum{} бит из n (от младшего к старшему)}} & `(n \textgreater{}\textgreater{} (m-1)) \& 1;` \tn % Row Count 22 (+ 5) % Row 18 \SetRowColor{white} {\bf{Получить m\textasciicircum{}ый\textasciicircum{} бит из n (от старшего к младшему)}} & `n \& \textasciitilde{}(1 \textless{}\textless{} (m-1));` \tn % Row Count 27 (+ 5) % Row 19 \SetRowColor{LightBackground} {\bf{Проверить включен ли n\textasciicircum{}ый\textasciicircum{} бит}} & ``if (x \& (1\textless{}\textless{}n)) \{ \{\{nl\}\}~ n-th bit is set \{\{nl\}\}\} else \{ \{\{nl\}\}~~n-th bit is not set \{\{nl\}\}\}` \tn % Row Count 33 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Целые (cont)}} \tn % Row 20 \SetRowColor{LightBackground} {\bf{Выделение самого правого \seqsplit{включенного} бита}} & `x \& (-x)` \tn % Row Count 5 (+ 5) % Row 21 \SetRowColor{white} {\bf{Выделение самого правого \seqsplit{выключенного} бита}} & `\textasciitilde{}x \& (x+1)` \tn % Row Count 10 (+ 5) % Row 22 \SetRowColor{LightBackground} {\bf{Выделение правого \seqsplit{включенного} бита}} & `x | (x+1)` \tn % Row Count 14 (+ 4) % Row 23 \SetRowColor{white} {\bf{Выделение правого \seqsplit{выключенного} бита}} & `x \& (x-1)` \tn % Row Count 18 (+ 4) % Row 24 \SetRowColor{LightBackground} {\bf{n + 1}} & `-\textasciitilde{}n` \tn % Row Count 19 (+ 1) % Row 25 \SetRowColor{white} {\bf{n – 1}} & `\textasciitilde{}-n` \tn % Row Count 20 (+ 1) % Row 26 \SetRowColor{LightBackground} {\bf{Получение \seqsplit{отрицательного} значения}} & `\textasciitilde{}n + 1; \{\{nl\}\}(n \textasciicircum{} -1) + 1;` \tn % Row Count 24 (+ 4) % Row 27 \SetRowColor{white} {\bf{if (x == a) x = b; \{\{nl\}\}if (x == b) x = a;}} & `x = a \textasciicircum{} b \textasciicircum{} x;` \tn % Row Count 27 (+ 3) % Row 28 \SetRowColor{LightBackground} {\bf{Поменять смежные биты}} & `((n \& 10101010) \textgreater{}\textgreater{} 1) | ((n \& 01010101) \textless{}\textless{} 1)` \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Целые (cont)}} \tn % Row 29 \SetRowColor{LightBackground} {\bf{Different rightmost bit of numbers m \& n}} & `(n\textasciicircum{}m)\&-(n\textasciicircum{}m)` // {\emph{returns 2\textasciicircum{}x\textasciicircum{} where x is the position of the different bit (0 based)}} \tn % Row Count 5 (+ 5) % Row 30 \SetRowColor{white} {\bf{Common rightmost bit of numbers m \& n}} & `\textasciitilde{}(n\textasciicircum{}m)\&(n\textasciicircum{}m)+1` // {\emph{returns 2\textasciicircum{}x\textasciicircum{} where x is the position of the common bit (0 based)}} \tn % Row Count 10 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Целые}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Округление до ближайшей степени двойки}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{unsigned int v; // работает только с 32 битными числами \{\{nl\}\}v-{}-; \{\{nl\}\}v |= v \textgreater{}\textgreater{} 1; \{\{nl\}\}v |= v \textgreater{}\textgreater{} 2; \{\{nl\}\}v |= v \textgreater{}\textgreater{} 4; \{\{nl\}\}v |= v \textgreater{}\textgreater{} 8; \{\{nl\}\}v |= v \textgreater{}\textgreater{} 16; \{\{nl\}\}v++;} \tn % Row Count 7 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Получение \seqsplit{максимального} целого}}} \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{int maxInt = \textasciitilde{}(1 \textless{}\textless{} 31); \{\{nl\}\}int maxInt = (1 \textless{}\textless{} 31) - 1; \{\{nl\}\}int maxInt = (1 \textless{}\textless{} -1) - 1; \{\{nl\}\}int maxInt = -1u \textgreater{}\textgreater{} 1;} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Получение минимального целого}}} \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{int minInt = 1 \textless{}\textless{} 31; \{\{nl\}\}int minInt = 1 \textless{}\textless{} -1;} \tn % Row Count 15 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Получение \seqsplit{максимального} long}}} \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`long maxLong = ((long)1 \textless{}\textless{} 127) - 1;`} \tn % Row Count 18 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Остаток от деления}}} \tn % Row Count 19 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{n \& 0b1; // на 2 \{\{nl\}\}n \& 0b11; // на 4 \{\{nl\}\}n \& 0b111; // на 8 \{\{nl\}\}{\emph{И так далее}}} \tn % Row Count 22 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Проверка равенства}}} \tn % Row Count 23 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(a\textasciicircum{}b) == 0; // {\emph{a == b}} \{\{nl\}\}!(a\textasciicircum{}b) // {\emph{использовать внутри if()}}} \tn % Row Count 25 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Обмен значениями}}} \tn % Row Count 26 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\emph{//version}} 1 \{\{nl\}\}a \textasciicircum{}= b; \{\{nl\}\}b \textasciicircum{}= a; \{\{nl\}\}a \textasciicircum{}= b;} \tn % Row Count 28 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\emph{ //version 2 }}\{\{nl\}\}a = a \textasciicircum{} b \textasciicircum{} (b = a)} \tn % Row Count 29 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Получение абсолютного значения}}} \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Целые (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\emph{//version 1}}\{\{nl\}\} x \textless{} 0 ? -x : x;} \tn % Row Count 1 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\emph{//version 2}} \{\{nl\}\}(x \textasciicircum{} (x \textgreater{}\textgreater{} 31)) - (x \textgreater{}\textgreater{} 31);} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Строки}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Конвертировать в нижний регистр}}`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(x | ' ') \{\{nl\}\}{\emph{Пример:}} `('a' | ' ') =\textgreater{} 'a' ; ('A' | ' ') =\textgreater{} 'a'`} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Конвертировать в верхний регистр}}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(x \& '\_') \{\{nl\}\} {\emph{Пример:}} `('a' \& '\_') =\textgreater{} 'A' ; ('A' \& '\_') =\textgreater{} 'A'`} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Инвертировать регистр}}} \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(x \textasciicircum{} ' ') \{\{nl\}\}{\emph{Пример:}} `('a' \textasciicircum{} ' ') =\textgreater{} 'A' ; ('A' \textasciicircum{} ' ') =\textgreater{} 'a'`} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Позиция буквы в алфавите (англ)}}} \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(x \& "\textbackslash{}x1F") \{\{nl\}\}{\emph{Пример:}} `('a' \& "\textbackslash{}x1F") =\textgreater{} 1 ; ('B' \& "\textbackslash{}x1F") =\textgreater{} 2`} \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Позиция большой буквы в алфавите (англ)}}} \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`(x \& '?')` {\emph{или}} `(x \textasciicircum{} '@')` \{\{nl\}\}{\emph{Пример:}} `('C' \& '?') =\textgreater{} 3 ; ('Z' \textasciicircum{} '@') =\textgreater{} 26`} \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Позиция строчной буквы в алфавите (англ)}}} \tn % Row Count 21 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{(x \textasciicircum{} '`') \{\{nl\}\}{\emph{Пример: }}`('d' \textasciicircum{} '`') =\textgreater{} 4 ; ('x' \textasciicircum{} '`') =\textgreater{} 24`} \tn % Row Count 23 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Десятичные дроби}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Примечание: хаки с float могут не работать на Ардуино! Разбить float в массив бит (unsigned uint32\_t)}}} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\#include \textless{}stdint.h\textgreater{} \{\{nl\}\}typedef union \{float flt; uint32\_t bits\} lens\_t; \{\{nl\}\}uint32\_t f2i(float x) \{ \{\{nl\}\}~~return ((lens\_t) \{.flt = x\}).bits; \{\{nl\}\}\}} \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Вернуть массив бит обратно в float}}} \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{float i2f(uint32\_t x) \{ \{\{nl\}\}~~return ((lens\_t) \{.bits = x\}).flt; \{\{nl\}\}\}} \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Быстрый обратный квадратный корень}}} \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`return i2f(0x5f3759df - f2i(x) / 2);`} \tn % Row Count 15 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Быстрый n\textasciicircum{}ый\textasciicircum{} корень из целого числа} \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{float root(float x, int n) \{ \{\{nl\}\}\#DEFINE MAN\_MASK 0x7fffff \{\{nl\}\}\#DEFINE EXP\_MASK 0x7f800000 \{\{nl\}\}\#DEFINE EXP\_BIAS 0x3f800000 \{\{nl\}\}~~uint32\_t bits = f2i(x); \{\{nl\}\}~~uint32\_t man = bits \& MAN\_MASK; \{\{nl\}\}~~uint32\_t exp = (bits \& EXP\_MASK) - EXP\_BIAS; \{\{nl\}\}~~return i2f((man + man / n) | ((EXP\_BIAS + exp / n) \& EXP\_MASK)); \{\{nl\}\}\}} \tn % Row Count 25 (+ 8) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Быстрая степень}}} \tn % Row Count 26 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{return i2f((1 - exp) {\emph{ (0x3f800000 - 0x5c416) + f2i(x) }} exp)} \tn % Row Count 28 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Быстрый натуральный логарифм}}} \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Десятичные дроби (cont)}} \tn % Row 11 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#DEFINE EPSILON 1.1920928955078125e-07 \{\{nl\}\}\#DEFINE LOG2 0.6931471805599453 \{\{nl\}\}return (f2i(x) - (0x3f800000 - 0x66774)) {\emph{ EPSILON }} LOG2} \tn % Row Count 3 (+ 3) % Row 12 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Быстрая экспонента}}} \tn % Row Count 4 (+ 1) % Row 13 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{return i2f(0x3f800000 + (uint32\_t)(x * (0x800000 + 0x38aa22)))} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Примечание: хаки с float могут не работать на Ардуино! Разбить float в массив бит (unsigned uint32\_t)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Другое}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Быстрая конвертация цвета R5G5B5 в R8G8B8}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{R8 = (R5 \textless{}\textless{} 3) | (R5 \textgreater{}\textgreater{} 2)} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{G8 = (R5 \textless{}\textless{} 3) | (R5 \textgreater{}\textgreater{} 2)} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{B8 = (R5 \textless{}\textless{} 3) | (R5 \textgreater{}\textgreater{} 2)} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Приоритет операций}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Чтобы не плодить скобки, нужно знать приоритет операций} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{++} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\&} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\%} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}=} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{?:} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}=} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Чтобы не плодить скобки, нужно знать приоритет операций} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Приоритет операций}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\emph{Чтобы не плодить скобки, нужно знать приоритет операций. В C++ он такой:}}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Приоритет операций}}} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{ :: ++ -{}- () {[}{]} . -\textgreater{} ++ -{}- + - ! \textasciitilde{} (type) * \& sizeof new, new{[}{]} delete, delete{[}{]} .* -\textgreater{}* * / \% + - \textless{}\textless{} \textgreater{}\textgreater{} \textless{} \textless{}= \textgreater{} \textgreater{}= == != \& \textasciicircum{} | \&\& || ?: = += -= *= /= \%= \textless{}\textless{}= \textgreater{}\textgreater{}= \&= \textasciicircum{}= |=:: ++ -{}- () {[}{]} . -\textgreater{} ++ -{}- + - ! \textasciitilde{} (type) * \& sizeof new, new{[}{]} delete, delete{[}{]} .* -\textgreater{}* * / \% + - \textless{}\textless{} \textgreater{}\textgreater{} \textless{} \textless{}= \textgreater{} \textgreater{}= == != \& \textasciicircum{} | \&\& || ?: = += -= *= /= \%= \textless{}\textless{}= \textgreater{}\textgreater{}= \&= \textasciicircum{}= |=}}} \tn % Row Count 13 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}