%--*- latex -*-----------------------------------------------------------------
%$Author: saulius $
%$Date: 2020-06-04 14:58:32 +0300 (Thu, 04 Jun 2020) $ 
%$Revision: 1524 $
%$URL: svn+ssh://saulius-grazulis.lt/home/saulius/svn-repositories/seminarai/2020-verifikacjos-seminarui/slides.tex $
%------------------------------------------------------------------------------

\documentclass[mathserif]{beamer}
\usetheme{Warwick}
\useoutertheme{infolines}
\setbeamertemplate{headline}{} % removes the headline the infolines inserts
%\setbeamertemplate{footline}[frame number]
\renewcommand\familydefault{\rmdefault}
% For XeLaTeX:
% https://tex.stackexchange.com/questions/452151/how-do-i-render-the-word-v%C7%ABlundarkvi%C3%B0a-with-bookman-and-xelatex
% "Use an OpenType clone of Bookman, for instance TeX Gyre Bonum":
\usepackage{fontspec}
\setmainfont{TeX Gyre Bonum}

\usepackage[style=authoryear,maxnames=1,doi=true,url=true,backend=biber]{biblatex}
%\addbibresource{bibliography/citations.bib}
\addbibresource{bibliography/Mitasiunas.bib}
%\addbibresource{bibliography/Murdocca.bib}
%\addbibresource{bibliography/Walker.bib}
\newcommand{\mycite}{\parencite}


\usepackage{multirow}

\usepackage{colordvi}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{chemfig}
\usepackage{listings}

% https://en.wikibooks.org/wiki/LaTeX/Algorithms
% http://mirror.datacenter.by/pub/mirrors/CTAN/macros/latex/contrib/algorithmicx/algorithmicx.pdf
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{amssymb}

\include{commands}

% https://tex.stackexchange.com/questions/595/how-can-i-get-bold-math-symbols:
\newcommand{\boldm}[1]{\mathversion{bold}#1\mathversion{normal}}

\newcommand{\RCSid}[1]{\fontsize{7pt}{7pt}\selectfont $#1$ \today}

%%BEGIN LANGUAGE lt
\title{Skaičiavimo sistemos. Dvejetainė aritmetika}
%%END LANGUAGE lt



\author{Saulius Gražulis}

\date{Vilnius, 2020}

% Define colors as in
% https://venngage.com/blog/color-blind-friendly-palette/ ``Retro''
\definecolor{Bluish}{HTML}{63ACBE}
\definecolor{Magentish}{HTML}{601A4A}
\definecolor{Orangish}{HTML}{EE442F}

\begin{document}

\colorlet{OnesComplementColor}{Magentish}
\colorlet{TwosComplementColor}{Bluish}
\colorlet{TwoToNthColor}{Orangish}

\colorlet{IdentifierColor}{red!40!black}
\colorlet{StringColor}{green!70!black}
\colorlet{KwdColor}{Bluish}
\colorlet{CommentColor}{Orangish}

%------------------------------------------------------------------------------

\begin{frame}
    \titlepage

\input{affiliation_lt}
    
    \begin{center}
      \mbox{}
      \hfill\hfill\hfill
      \includegraphics[height=1.5cm]{images/sp_VU_zenklas.eps}
      \hfill
      \includegraphics[height=1.5cm]{images/2019-05-02_Melynas_MIF-zenklas242x244.png}
      \hfill\hfill\hfill
      \mbox{}
    \end{center}

    \vfill

    %% \tiny
    %% \RCSid{
    %%   $Id: slides.tex 1524 2020-06-04 11:58:32Z saulius $
    %% }
    \begin{flushright}
      \begin{minipage}[c]{0.67\textwidth}
        \tiny\raggedright
        %%BEGIN LANGUAGE lt
        Šį skaidrių rinkinį galima kopijuoti,
        kaip nurodyta Creative Commons
        %%END LANGUAGE lt
        \myhref{http://creativecommons.org/licenses/by-sa/4.0/}{Attribution-ShareAlike
          4.0 International}
licenzijoje
      \end{minipage}
      %%
      \begin{minipage}[c]{1.5cm}
        \myhref{http://creativecommons.org/licenses/by-sa/4.0/}{
          \includegraphics[width=1.5cm]{images/CC-BY-SA.eps}
        }
      \end{minipage}
    \end{flushright}

\end{frame}

%==============================================================================

\begin{frame}
\frametitle{Dvejetainė aritmetika}

  \begin{center}
    \small
    %%BEGIN LANGUAGE lt
    Skaitmenys, kuriuos galime atvaizduoti savo aparatūroje: \textbf{0} ir \textbf{1}
    %%END LANGUAGE lt
  \end{center}
  
  %% \footnotesize
  \scriptsize
  %% \fontsize{9}{10}\selectfont

  \newcommand{\rr}{\rule{4em}{0pt}}
  \newcommand{\rp}{\rule{2em}{0pt}}
  \begin{center}
    \begin{tabular}{|r|r|r|r|r|}
      \hline
Sistema:
      & dec      & bin    & oct    & hex     \\
Pagr.:
      & \rp{}10  & \rr{}2 & \rp{}8 & \rp{}16 \\
      \hline
      & \only<2->{0}  & \only<10->{    0} & \only<21->{  0} & \only<24->{  0} \\
      & \only<3->{1}  & \only<11->{    1} & \only<21->{  1} & \only<24->{  1} \\
      &
        \only<33>{\bf\em}
        \only<4->{2}  &
                        \only<33>{\bf\color{red}}
                        \only<12>{\color{red}\bf}
                        \only<12->{1}\only<12>{\color{black}}\only<12->{0}
                                          & \only<21->{  2} & \only<24->{  2} \\
      & \only<5->{3}  & \only<13->{   11} & \only<21->{  3} & \only<24->{  3} \\
      &
        \only<33>{\bf\em}
        \only<6->{4}  &
                        \only<33>{\bf\color{red}}
                        \only<14>{\color{red}\bf}
                        \only<14->{1}\only<14>{\color{black}}\only<14->{00}
                                          & \only<21->{  4} & \only<24->{  4} \\
      & \only<6->{5}  & \only<15->{  101} & \only<21->{  5} & \only<24->{  5} \\
      & \only<6->{6}  & \only<16->{  110} & \only<21->{  6} & \only<24->{  6} \\
      & \only<6->{7}  & \only<17->{  111} & \only<21->{  7} & \only<24->{  7} \\
      &
        \only<33>{\bf\em}
        \only<6->{8}  &
                        \only<34>{\bf\color{blue}}
                        \only<33>{\bf\color{red}}
                        \only<18>{\color{red}\bf}
                        \only<18->{1}\only<18>{\color{black}}\only<18->{000}
                                          &
                                            \only<34>{\bf\color{blue}}
                                            \only<33>{\bf\color{red}}
                                            \only<22->{ 10} & \only<24->{  8} \\
      & \only<6->{9}  & \only<19->{ 1001} & \only<23->{ 11} & \only<24->{  9} \\
      &
        \only<33>{\bf\color{red}}
        \only<7>{\color{red}\bf}
        \only<7->{1}\only<7>{\color{black}}\only<7->{0}
                      & \only<20->{ 1010} & \only<23->{ 12} & \only<25->{  A} \\
      & \only<8->{11} & \only<20->{ 1011} & \only<23->{ 13} & \only<26->{  B} \\
      & \only<9->{12} & \only<20->{ 1100} & \only<23->{ 14} & \only<27->{  C} \\
      & \only<9->{13} & \only<20->{ 1101} & \only<23->{ 15} & \only<28->{  D} \\
      & \only<9->{14} & \only<20->{ 1110} & \only<23->{ 16} & \only<29->{  E} \\
      & \only<9->{15} & \only<20->{ 1111} & \only<23->{ 17} & \only<30->{  F} \\
      &
        \only<33>{\bf\em}
        \only<9->{16} &
                        \only<34>{\bf\color{blue}}
                        \only<33>{\bf\color{red}}
                        \only<20->{10000} &
                                            \only<34>{\bf\color{blue}}
                                            \only<23->{ 20} &
                                                              \only<34>{\bf\color{blue}}
                                                              \only<33>{\bf\color{red}}
                                                              \only<31->{ 10} \\
      & \only<9->{17} & \only<20->{10001} & \only<23->{ 21} & \only<32->{ 11} \\
      \hline
    \end{tabular}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Skaičių reiškimas}

  %%BEGIN LANGUAGE lt
  Sistemoje pagrindu $b$, $m$ skaitmenų skaičius atvaizduojamas kaip daugianaris:
  %%END LANGUAGE lt
  $$
  N = a_{m-1}b^{m-1} + a_{m-2}b^{m-2} + \dots + a_2b^2 + a_1b + a_0
  $$

Pavyzdys:

  $$
  \begin{array}{rl}
    110101_2
    & = 1\cdot2^5 + 1\cdot2^4 + 0\cdot2^3 + 1\cdot2^2 + 0\cdot2^1 + 1\cdot2^0 \\
    & = 32_{10} + 16_{10} + 4_{10} + 1_{10} \\
    & = 53_{10} \\
  \end{array}
  $$
  
Kitas pavyzdys:

  $$
  16_{16} = 1\cdot16^1 + 6\cdot16^0 = 16_{10} + 6_{10} = 22_{10}
  $$
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Trupmenų reiškimas}

  %%BEGIN LANGUAGE lt
  Sistemoje pagrindu $b$, trupmena $f = 0.a_1a_2\dots{}a_m$ atvaizduojama
  kaip daugianaris:
  %%END LANGUAGE lt
  $$
  f = a_1b^{-1} + a_2b^{-2} + \dots + a_{m-1}b^{-m+1} + a_mb^{-m}
  $$

  Example:

  $$
  \begin{array}{rcl}
    0.0110101_2
    & = &
    0\cdot2^{-1} + 1\cdot2^{-2} + 1\cdot2^{-3} + 0\cdot2^{-4} + \\
    && +
    1\cdot2^{-5} + 0\cdot2^{-6} + 1\cdot2^{-7}
    \\
    \\
    & = &
    \frac{1}{4_{10}} + \frac{1}{8_{10}} + \frac{1}{32_{10}} +
    \frac{1}{128_{10}}
    \\
    \\
    & = &
    0.4140625_{10}
  \end{array}
  $$
  
\end{frame}

%------------------------------------------------------------------------------

\newcommand{\divByTwo}{\multicolumn{1}{|l}{$2_{10}$}}
\newcommand{\divByTwoN}[1]{\multicolumn{1}{|l}{\only<#1>{\color{white}}$2_{10}$}}
\newcommand{\rmth}[1]{\boldm{$\color{red}#1$}}
\newcommand{\rmthN}[2]{\only<#2>{\boldm{$\color{red}#1$}}}
\newcommand{\emptycline}[1]{}

\begin{frame}
\frametitle{Pavertimas į kitas skaičiavimo sistemas}

  \small
  %%BEGIN LANGUAGE lt
  Dalyba iš sistemos bazės duoda liekaną, kuri yra jauniausias
  skaičiaus skaitmuo:
  %%END LANGUAGE lt
  \only<1>{
    $$
    \begin{array}{rl}
      N
      & = a_{m-1}b^{m-1} + a_{m-2}b^{m-2} + \dots + a_2b^2 + a_1b + a_0
      \\
      & = b ( a_{m-1}b^{m-2} + a_{m-2}b^{m-3} + \dots + a_2b + a_1 ) + a_0
    \end{array}
    $$
  }
  \only<2->{
    $$ 100110_2 / 10_2 = 10011.0_2 \quad \text{(quotient} = 10011_2,
    \text{reminder} = 0\text{)} $$
    $$ 10011_2 / 10_2 = 1001.1_2 \quad \text{(quotient} = 1001_2,
    \text{reminder} = 1\text{)} $$
  }

  \only<1>{\color{white}}
  \only<1>{\renewcommand{\cline}{\emptycline}}
  \only<1>{\renewcommand{\divByTwoN}{}}

  %%BEGIN LANGUAGE lt
  Taigi, pakartotinė dalyba iš sistemos \textit{pagrindo} duoda mums
  visus skaitmenis toje sistemoje kaip dalybos \textit{liekanas}:
  %%END LANGUAGE lt

  \begin{center}
    \begin{tikzpicture}
      \node (table) {
        \begin{tabular}{llllllll}
          $\mathbf{38}$      & \divByTwo \\
          \cline{2-2}
          \only<3->{$\mathbf{38}$} & \only<3->{$19$} & \divByTwoN{1-4} \\
          \cline{1-1}\cline{3-3}
          \rmthN{0}{4-}   & \only<6->{$18$} & \only<6->{$9$} & \divByTwoN{1-7} \\
          \cline{2-2}\cline{4-4}
                          & \rmthN{1}{7-}   & \only<9->{$8$} & \only<9->{$4$}  & \divByTwoN{1-10} \\
          \cline{3-3}\cline{5-5}
                          &                 & \rmthN{1}{10-} & \only<12->{$4$} & \only<12->{$2$} & \divByTwoN{1-13} \\
          \cline{4-4}\cline{6-6}
                          &                 &                & \rmthN{0}{13-}  & \only<15->{$2$} & \only<15->{$1$} & \divByTwoN{1-16} \\
          \cline{5-5}\cline{7-7}
                          &                 &                &                 & \rmthN{0}{16-}  & \only<18->{$0$} & \only<18->{$0$} \\
          \cline{6-6}\cline{8-8}
                          &                 &                &                 &                 & \rmthN{1}{19-} \\
        \end{tabular}
      };
      \only<20->{
        \draw [red,thick,->] (2,-2) to (-3,0.4);
      }
      \node (empty) at (2,-2) {};
    \end{tikzpicture}
  \end{center}

  \vspace{-\baselineskip}
  \rule[-0.3\baselineskip]{0pt}{1\baselineskip}
  \only<21>{$ 100110_2 = 2^5 + 2^2 + 2^1 = 32_{10} + 4_{10} + 2_{10} = \mathbf{38_{10}} $}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Trupmenų pavertimas}

  \small

  %%BEGIN LANGUAGE lt
  Trupmenas galime padauginti iš skaičiavimo sistemos bazės ir gauti
  vieną po kito skaitmenis už trupmenos kablelio:
  %%END LANGUAGE lt

  \only<1-6>{
    \begin{center}
      \begin{tikzpicture}
        \node (conv) at (0,0) {
          \renewcommand{\arraystretch}{1.5}
          \begin{tabular}{c}
            \only<1>{\color{white}}
            $
            0.01101_2 \times 10_2 = 0.1101_2; \quad \lfloor 0.01101_2 \times
            10_2 \rfloor = \lfloor 0.1101_2 \rfloor =
            \mathbf{
              \only<2->{\color{red}}0
            }
            $
            \\
            \only<1-2>{\color{white}}
            $
            \mathbf{0}.1101_2 \times 10_2 = 1.101_2; \lfloor 0.1101_2 \times
            10_2 \rfloor =  \lfloor 1.101_2 \rfloor =
            \mathbf{
              \only<3->{\color{red}}1
            }
            $
            \\
            \only<1-3>{\color{white}}
            $
            1.101_2 - \lfloor 1.101_2 \rfloor = \mathbf{0}.101_2
            $
            \\
            \only<1-4>{\color{white}}
            $
            \mathbf{0}.101_2 \times 10_2 = 1.01_2; \lfloor 1.01_2 \rfloor =
            \mathbf{
              \only<5->{\color{red}}1
            }
            $
            \\
            \only<6->{\dots}
          \end{tabular}
        };
        % 'conv.10' means ancor at the node 'conv' rotated 10 degrees
        % counterclockwise:
        \only<6->{
          \draw [thick,red,->] (conv.5) to ([yshift=1\baselineskip] conv.-30);
        }
        % These strategically placed empty nodes keep the size of the image
        % constant during the '\only<...' cycling:
        \node (empty) at (-5.5,0) {};
        \node (empty) at (5.5,0)  {};
        \node (empty) at (0,-1.5) {};
      \end{tikzpicture}
    \end{center}
  }

  \only<7-16>{
    \begin{center}
Paverskime
      $\mathbf{0.625_{10}}$
į dvejetainę sistemą.
      
      \begin{tikzpicture}
        \node (conv) at (0,0) {
          \renewcommand{\arraystretch}{1.5}
          \begin{tabular}{c}
            \only<7>{\color{white}}
            $
            0.625_{10} \times 2_{10} = 1.25_{10}; \quad \lfloor 0.625_{10}
            \times 2_{10} \rfloor = \lfloor 1.25_{10} \rfloor =
            \mathbf{
              \only<8->{\color{red}}1
            }
            $
            \\
            \only<7-8>{\color{white}}
            $
            1.25_{10} - \lfloor 1.25_{10} \rfloor = 0.25_{10}
            $
            \\
            \only<7-9>{\color{white}}
            $
            0.25_{10} \times 2_{10} = 0.5_{10}; \quad \lfloor 0.25_{10} \times
            2_{10} \rfloor = \lfloor 0.5_{10} \rfloor =
            \mathbf{
              \only<10->{\color{red}}0
            }
            $
            \\
            \only<7-10>{\color{white}}
            $
            0.5_{10} - \lfloor 0.5_{10} \rfloor = 0.5_{10}
            $
            \\
            \only<7-11>{\color{white}}
            $
            0.5_{10} \times 2_{10} = 1.0_{10}; \lfloor 1.0_{10} \rfloor =
            \mathbf{
              \only<12->{\color{red}}1
            }
            $
            \\
            \only<7-12>{\color{white}}
            $
            1.0_{10} - \lfloor 1.0_{10} \rfloor = 1 - 1 = 0 \Rightarrow
            \text{\bf end}
            $
          \end{tabular}
        };
        % 'conv.10' means ancor at the node 'conv' rotated 10 degrees
        % counterclockwise:
        \only<14->{
          \draw [thick,red,->] (conv.10) to ([yshift=2\baselineskip] conv.-30);
        }
        % These strategically placed empty nodes keep the size of the image
        % constant during the '\only<...' cycling:
        \node (empty) at (-5.5,0) {};
        \node (empty) at (5.5,0)  {};
        \node (empty) at (0,-2)   {};
      \end{tikzpicture}
    \end{center}
  }

  \rule[-0.3\baselineskip]{0pt}{1.5\baselineskip}
  \only<15>{
    $0.101_2$
  }
  \only<16>{
    $0.101_2 = 1\cdot2^{-1} + 0\cdot2^{-2} + 1\cdot2^{-3} = 0.5_{10} + 0.125_{10} =
    \mathbf{0.625_{10}}$
  }
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Pavertimas į aštuonetainę ir šešioliktainę sistemas}

  \small
  
Dalyba iš $8_{10}$ atitinka \textbf{3} dvejetainių skaitmenų atskyrimą:
  $$
  1101\,1011_2 / 8_{10} \equiv 1101\,1011_2 / 1000_{2} = 1101\,1.\mathbf{011}_2
  $$
  
Dalyba iš $16_{10}$ atitinka \textbf{4} dvejetainių skaitmenų atskyrimą:
  $$
  1101\,1011_2 / 16_{10} \equiv 1101\,1011_2 / 10000_{2} = 1101\,.\mathbf{1011}_2
  $$


  \textcolor{blue}{
    \fbox{
      \parbox{0.94\linewidth}{
        %%BEGIN LANGUAGE lt
        $\Rightarrow$ Norint paversti į aštuonetainę (šešioliktainę) sistemą,
        reikia su\-gru\-puo\-ti dvejetainius skaitmenis po 3 (4) ir paversti
        kiekvieną grupę į atitinkamą kitos sistemos skaitmenį:
        %%END LANGUAGE lt
      }
    }
  }

  \scriptsize  
  \begin{center}
    \begin{minipage}{0.2\textwidth}
      \begin{tabular}{ll}
        \multicolumn{2}{l}{
Aštuonetainiai
        }
        \\
        000 & 0 \\
        001 & 1 \\
        010 & 2 \\
        011 & 3 \\
        100 & 4 \\
        101 & 5 \\
        110 & 6 \\
        111 & 7 \\
      \end{tabular}
    \end{minipage}
    \begin{minipage}{0.45\textwidth}
      $\longleftarrow$
      
Pavyzdys (aštuonetainis):
      
      $ 01011011_2 = \mathbf{{\color{gray}0}01\;011\;011_2} = \mathbf{133_8} $

      \vspace{\baselineskip}
      \rightline{$\longrightarrow$}
      
      \rightline{
Pavyzdys (šešioliktainis):
      }
      
      $ 01011011_2 = \mathbf{0101\;1011_2} = \mathbf{5\mathrm{\mathbf{B}}_{16}} $
    \end{minipage}
    \begin{minipage}{0.3\textwidth}
      \begin{tabular}{ll|ll}
        \multicolumn{4}{c}{
Šešioliktainiai skaitmenys
        }
        \\
        0000 & 0 & 1000 & 8 \\
        0001 & 1 & 1001 & 9 \\
        0010 & 2 & 1010 & A \\
        0011 & 3 & 1011 & B \\
        0100 & 4 & 1100 & C \\
        0101 & 5 & 1101 & D \\
        0110 & 6 & 1110 & E \\
        0111 & 7 & 1111 & F \\
      \end{tabular}
    \end{minipage}
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\lstset{
  keywordstyle=\color{TwosComplementColor}\bfseries,
  basicstyle=\ttfamily\footnotesize
}

\begin{frame}[containsverbatim]
\frametitle{XXI~a.: pavertimas naudojant kompiuterį}

  \small
  
Aprašymas:
  
  \begin{lstlisting}[language=bash,frame=trBL,morekeywords={perl,print}]
    man perlfaq4
  \end{lstlisting}

Dvejetainė $\rightarrow$ dešimtainė:
  
  \begin{lstlisting}[language=bash,frame=trBL,morekeywords={perl,print}]
    perl -le 'print 0b_0110_1011'
    107
  \end{lstlisting}
  
Šešioliktainė $\rightarrow$ dvejetainė:
  
  \begin{lstlisting}[language=bash,frame=trBL,morekeywords={perl,print}]
    perl -e 'printf "%016b\n", 0x23FF'
    0010001111111111
  \end{lstlisting}
  
Aštuonetainė $\rightarrow$ šešioliktainė:
  
  \begin{lstlisting}[language=bash,frame=trBL,morekeywords={perl,print}]
    perl -e 'printf "%02X\n", 0133'
    5B
  \end{lstlisting}

Dėmesio: šis metodas veikia tik mažiems skaičiams
  ($|n| < 2^{31}$)!
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}[containsverbatim]
\frametitle{XXI~a.: trupmenų pavertimas}

  \small

Paverskime trupmeną
  $0.0110\,1011_2 = 0110\,1011_2 / 1\,0000\,0000_2$
į dešimtainę sistemą:

  \vspace{\baselineskip}
  \begin{lstlisting}[language=bash,frame=trBL,morekeywords={perl,print}]
perl -le 'print 0b_0110_1011 / (2**8)'
0.41796875
  \end{lstlisting}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}[containsverbatim]
\frametitle{XXI~a.: trupmenų pavertimas}

  \small

Paverskime trupmeną
  $0.0110\,1011_2 = 0110\,1011_2 / 1\,0000\,0000_2$
į dešimtainę sistemą:

  \vspace{\baselineskip}
  \begin{lstlisting}[language=bash,frame=trBL,morekeywords={perl,print}]
perl -le 'print 0b_0110_1011 / (2**8)'
0.41796875
  \end{lstlisting}

Patikrinkime:
  
  \begin{lstlisting}[basicstyle=\ttfamily\tiny,language=bash,frame=trBL,morekeywords={perl,print}]
perl -e '$x=0.41796875; print "0."; while($x) {$x*=2; print int($x); $x-=int($x)}; print "\n"'
0.01101011
  \end{lstlisting}

  %%BEGIN LANGUAGE lt
  Dėmesio! Šis metodas veikia \textbf{\textit{tik}} tada, jeigu
  trupmenos \textbf{tiksliai} atvaizduojamos mūsų kompiuteryje!
  %%END LANGUAGE lt

\end{frame}

%------------------------------------------------------------------------------

\lstset{
  language=perl,
  keywordstyle=\color{KwdColor},
  commentstyle=\color{CommentColor}\ttfamily,
  identifierstyle=\color{IdentifierColor},
  stringstyle=\color{StringColor},
  basicstyle=\ttfamily\tiny
}

\begin{frame}[containsverbatim]
\frametitle{Paverskime $0.1_{10}$}

  \small
  \vspace{-\baselineskip}
  
  $$
  0.1_{10} = 1/10_{10}
  $$

Failas:
  \texttt{"examples/code/one-tenth.c"}
  \lstinputlisting[language=C,basicstyle=\ttfamily\tiny,frame=trBL,
    linerange={1-12,17-30}]
                  {examples/code/one-tenth.c}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}[containsverbatim]
\frametitle{Paverskime $0.1_{10}$}

  \small
  \vspace{-\baselineskip}
  
  $$
  0.1_{10} = 1/10_{10}
  $$

  \begin{lstlisting}[basicstyle=\ttfamily\tiny,language=bash,frame=trBL,morekeywords={perl,print}]
sh$ examples/code/one-tenth
0.0001 1001 1001 1001 1001
  \end{lstlisting}
  $$
  0.1_{10} = 0.0001\,\overline{1001}_2
  $$

Begalinė dvejetainė trupmena!

  \vspace{\baselineskip}
  \color{blue}
  \fbox{
    \parbox{0.9\textwidth}{
      %%BEGIN LANGUAGE lt
      Jei pilnai suprastintos trupmenos vardiklis turi pirminių
      daugiklių, iš kurių \textbf{\textit{nesidalina}} skaičių sistemos
      bazė, tokioje bazėje ši trupmena bus begalinė periodinė.
      %%END LANGUAGE lt
    }
  }

  \vspace{\baselineskip}
  \color{black}
  E.g. $1/10_{10}$:
  $$
  \begin{array}{rl}
    10_{10} = 2 \times 5; & 5 \ \text{
nėra skaičiaus
    }\ 2
\ \text{daliklis}
    \\
    \Rightarrow & 1/10_{10} = 0.0001\,\overline{1001}_2 \ \text{
– begalinė periodinė
    } \\
  \end{array}
  $$
  
\end{frame}

%------------------------------------------------------------------------------

% Black digit:
\newcommand{\bd}[2]{\only<#1>{#2}}
% Red digit:
\newcommand{\rd}[2]{\only<#1>{\color{TwoToNthColor}#2}}
% Gray digit:
\newcommand{\gd}[2]{\only<#1>{\color{gray}#2}}

\begin{frame}
\frametitle{Dvejetainė aritmetika}

  \only<1-2>{
    \begin{quote}
      \footnotesize
      /.../ Būtinas minimumas yra sudėtis, nes atimtis tai yra sudėtis su
      papildomu kodu, daugyba – daug sudėčių cikle, o dalyba – daug
      atimčių.


    \end{quote}
    \rightline{
      \begin{minipage}{0.4\textwidth}
        \scriptsize
        Antanas Mitašiūnas \parencite*{Mitasiunas2016} \\
        ``Kompiuterių architektūra“, p.~9
      \end{minipage}
    }
    \vspace{\baselineskip}
  }
  
  \begin{center}
    \begin{minipage}{0.4\textwidth}
      \begin{center}
Sudėtis:
        $$ A + B $$
        \begin{tabular}{rr|rr}
          & \multicolumn{1}{l}{} & \multicolumn{2}{c}{B} \\
          & $+$ &  0 & 1 \\
          \cline{2-4}
          \multirow{2}{*}{A}
          & 0   &  0 & 1 \\  
          & 1   &  1 & \textcolor{TwoToNthColor}{1}0 \\  
        \end{tabular}
      \end{center}
    \end{minipage}
    \begin{minipage}{0.4\textwidth}
      \only<2->{
        \begin{center}
Daugyba:
          $$ A \times B $$
          \begin{tabular}{rr|rr}
            & \multicolumn{1}{l}{} & \multicolumn{2}{c}{B} \\
            & $\times$ &  0 & 1 \\
            \cline{2-4}
            \multirow{2}{*}{A}
            & 0   &  0 & 0 \\  
            & 1   &  0 & 1 \\  
          \end{tabular}
        \end{center}
      }
    \end{minipage}
  \end{center}

  \rule[-1.7cm]{0pt}{3.5cm}
  \begin{minipage}[t]{0.4\textwidth}
    \only<3->{
      \begin{center}
        \setlength{\tabcolsep}{0pt}
        \begin{tabular}{rcccccc}
          \multirow{4}{*}{$+$}
          &     \rd{8-}{1} & \rd{7-}{1} &            &            & \rd{4-}{1} &   \\
          & \color{white}0 &         1  &         1  &         1  &         0  & 1 \\
          &                &         1  &         1  &         0  &         0  & 1 \\
          \hline
          &     \bd{9-}{1} & \bd{8-}{1} & \bd{7-}{0} & \bd{6-}{1} & \bd{5-}{1} & \bd{4-}{0} \\
        \end{tabular}
      \end{center}
    }
  \end{minipage}
  \begin{minipage}[t]{0.4\textwidth}
    \only<10->{
      \begin{center}
        \setlength{\tabcolsep}{0pt}
        \begin{tabular}{rccccccc}
          \multirow{2}{*}{$\times$}
          \color{white}0   &
          \color{white}0   &
          \color{white}0   &         1   &          1  &          0  &          1 \\
          &&               &             &          1  &          0  &          1 \\
          \hline
          \only<1-13>{
            &&&& \\
          }
          \only<14->{
            & \rd{14-}{1} & \rd{14-}{1} & \rd{14-}{1} \\
          }
          &&                & \bd{11-}{1} & \bd{11-}{1} & \bd{11-}{0} & \bd{11-}{1} \\
          &&    \gd{12-}{0} & \gd{12-}{0} & \gd{12-}{0} & \gd{12-}{0} \\
          &\bd{13-}{1}
          & \bd{13-}{1} & \bd{13-}{0} & \bd{13-}{1} \\
          \hline
          \only<14->{
            \bd{14-}{1} & \bd{14-}{0} & \bd{14-}{0} & \bd{14-}{0} & \bd{14-}{0} &
            \bd{14-}{0} & \bd{14-}{1} & \\
          }
        \end{tabular}
      \end{center}
    }
  \end{minipage}
  
\end{frame}

%------------------------------------------------------------------------------

\newcommand{\Rc}{\color{TwoToNthColor}}
\newcommand{\Bc}{\color{TwosComplementColor}}
\newcommand{\Yc}{\color{black}}

\begin{frame}
\frametitle{Loginės operacijos pabičiui}

  %%BEGIN LANGUAGE lt
  Vieną dvejetainę skiltį skaičiuje trumpai vadinsime \textit{bitu},
  iš anglų kalbos \textit{binary digit}.
  %%END LANGUAGE lt

  \vfill
  %%BEGIN LANGUAGE lt
  Naudingos loginės operacijos pabičiui:
  %%END LANGUAGE lt
    
  \vfill
  \vfill
  \begin{minipage}{0.45\textwidth}
Pasirinkti (maskuoti) bitus:
    $$
    \begin{array}{rr}
      &1101\,1010\,0111 \\
      \text{AND}&
      \color{black}000\color{TwoToNthColor}1\,1111\,1\color{black}000 \\
      &\text{\rule[0.9\baselineskip]{6em}{0.5pt}} \\
      &\color{gray}
      000\color{TwosComplementColor}1\,1010\,0\color{gray}000
    \end{array}
    $$
  \end{minipage}
  \hspace{0.5em}
  \only<2->{
    \begin{minipage}{0.45\textwidth}
Nustatyti bitus:
      $$
      \begin{array}{rr}
        &1101\,1010\,0111 \\
        \text{OR}&
        \color{black}000\color{TwoToNthColor}1\,1111\,1\color{black}000 \\
        &\text{\rule[0.9\baselineskip]{6em}{0.5pt}} \\
        &\color{gray}
        110\color{TwosComplementColor}1\,1111\,1\color{gray}111
      \end{array}
      $$
    \end{minipage}
  }

  \vfill
  \parbox[b]{0pt}{
    \rule{0pt}{3.2\baselineskip}
  }
  \begin{minipage}[b]{0.95\textwidth}
    \only<3->{
Klausimai:
      $$
      2\mathrm{B} \ \text{OR}\ \text{NOT}\ 2\mathrm{B} = \text{??}
      $$
    }
  \end{minipage}

  \parbox[c]{0pt}{
    \rule[-\baselineskip]{0pt}{2\baselineskip}
  }
  \begin{minipage}[c]{0.95\textwidth}
    \only<4->{
      %%BEGIN LANGUAGE lt
      Kokią bitų kaukę galima naudoti, norint patikrinti, ar skaičius yra
      lyginis?
      %%END LANGUAGE lt
    }
  \end{minipage}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Intuityvus informacijos kiekio supratimas}

  %%BEGIN LANGUAGE lt
  Išsiaiškinti, kuris simbolis buvo perduotas, užduodant taip/ne
  klausimus:
  %%END LANGUAGE lt
   ``A'', ``B'', ``1'', ``2''.
  
  \begin{center}
\footnotesize
    \begin{tikzpicture}
      \node (A) {
raidė/skaitmuo?
      };
      \node (B) [below left  = of A] {
balsė/priebalsė?
      };
      \node (C) [below right = of A] {
lyginis/nelyginis?
      };
      \node (D) [below left  = of B, xshift=+1cm] {``Α''};
      \node (E) [below right = of B, xshift=-1cm] {``Β''};
      \node (F) [below left  = of C, xshift=+1cm] {``1''};
      \node (G) [below right = of C, xshift=-1cm] {``2''};
      \draw [->,thick] (node cs: name=A) -- (node cs: name=B);
      \draw [->,thick] (node cs: name=A) -- (node cs: name=C);
      \draw [->,thick] (node cs: name=B) -- (node cs: name=D);
      \draw [->,thick] (node cs: name=B) -- (node cs: name=E);
      \draw [->,thick] (node cs: name=C) -- (node cs: name=F);
      \draw [->,thick] (node cs: name=C) -- (node cs: name=G);
    \end{tikzpicture}
  \end{center}

  \vspace{-2\baselineskip}
  \begin{center}
    \renewcommand{\arraystretch}{1.2}
    $$
    \begin{array}{c}
      N_{\text{\rm{symbols}}} =
      N_{\text{\rm{leaves}}} =
      2^{n_{\text{\rm{questions}}}} =
      2^{n_{\text{\rm{layers}}}}
      \\
      n_{\text{\rm{questions}}} =
      n_{\text{\rm{layers}}} =
      \log_2 N_{\text{\rm{symbols}}} =
      \log_2 \frac{1}{p_{\text{\rm{symbol}}}} =
      - \log_2 p_{\text{\rm{symbol}}}
      \\
      n_\text{q} = \log_2 N_\text{s} = \log_2 4 = - \log_2 \frac{1}{4} = \log_2 2^2 = 2
    \end{array}
    $$
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Intuityvus informacijos kiekio supratimas (2)}

  %%BEGIN LANGUAGE lt
  Vienas iš 8 simbolių:
  %%END LANGUAGE lt
   ``A'', ``B'', ``E'', ``F'', ``1'', ``2'', ``3'', ``4''.
  
  \begin{center}
\resizebox{!}{3.1cm}{
      %% https://tex.stackexchange.com/questions/4338/correctly-scaling-a-tikzpicture:
      \begin{tikzpicture}
        \node (A) {
raidė/skaitmuo?
        };
        \node (B) [below left  = of A, xshift=-1cm] {
balsė/priebalsė?
        };
        \node (C) [below right = of A, xshift=+1cm] {
lyginis/nelyginis?
        };
        \node (D) [below left  = of B, xshift=+2cm] {
mažesnis/didesnis?
        };
        \node (E) [below right  = of B, xshift=-2cm] {
mažesnis/didesnis?
        };
        \node (F) [below left  = of C, xshift=+1.5cm] {
mažesnis/didesnis?
        };
        \node (G) [below right  = of C, xshift=-1.5cm] {
mažesnis/didesnis?
        };
        \node (n1) [below left  = of D, xshift=+2cm] {``Α''};
        \node (n2) [below right = of D, xshift=-2cm] {``E''};
        \node (n3) [below left  = of E, xshift=+2cm] {``B''};
        \node (n4) [below right = of E, xshift=-2cm] {``F''};

        \node (n5) [below left  = of F, xshift=+2cm] {``1''};
        \node (n6) [below right = of F, xshift=-2cm] {``3''};
        \node (n7) [below left  = of G, xshift=+2cm] {``2''};
        \node (n8) [below right = of G, xshift=-2cm] {``4''};

        \draw [->,thick] (node cs: name=A) -- (node cs: name=B);
        \draw [->,thick] (node cs: name=A) -- (node cs: name=C);
        \draw [->,thick] (node cs: name=B) -- (node cs: name=D);
        \draw [->,thick] (node cs: name=B) -- (node cs: name=E);
        \draw [->,thick] (node cs: name=C) -- (node cs: name=F);
        \draw [->,thick] (node cs: name=C) -- (node cs: name=G);

        \draw [->,thick] (node cs: name=D) -- (node cs: name=n1);
        \draw [->,thick] (node cs: name=D) -- (node cs: name=n2);

        \draw [->,thick] (node cs: name=E) -- (node cs: name=n3);
        \draw [->,thick] (node cs: name=E) -- (node cs: name=n4);

        \draw [->,thick] (node cs: name=F) -- (node cs: name=n5);
        \draw [->,thick] (node cs: name=F) -- (node cs: name=n6);

        \draw [->,thick] (node cs: name=G) -- (node cs: name=n7);
        \draw [->,thick] (node cs: name=G) -- (node cs: name=n8);

      \end{tikzpicture}
    }
  \end{center}

  \vspace{-2\baselineskip}
  \begin{center}
    \renewcommand{\arraystretch}{1.5}
    $$
    \begin{array}{c}
      N_{\text{\rm{symbols}}} =
      N_{\text{\rm{leaves}}} =
      2^{n_{\text{\rm{questions}}}} =
      2^{n_{\text{\rm{layers}}}}
      \\
      n_{\text{\rm{questions}}} =
      n_{\text{\rm{layers}}} =
      \log_2 N_{\text{\rm{symbols}}} =
      \log_2 \frac{1}{p_{\text{\rm{symbol}}}} =
      - \log_2 p_{\text{\rm{symbol}}}
      \\
      n_\text{q} = \log_2 N_\text{s} = \log_2 8 = -\log_2 \frac{1}{8} = \log_2 2^3 = 3
    \end{array}
    $$
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Informacijos kiekis priklauso nuo tikimybių}

  %%BEGIN LANGUAGE lt
  Vienas iš 4 simbolių:
  %%END LANGUAGE lt
   ``A'', ``B'', ``1'', ``2''

  \begin{center}
    ``AAA\textcolor{red}{1}AAA\textcolor{red}{B}A\textcolor{red}{1}A\textcolor{red}{2}AAA\textcolor{red}{1}AAAA''

    \footnotesize
    (20
simbolių
    )
  \end{center}

  \begin{center}
    \resizebox{!}{3.5cm}{
      %% https://tex.stackexchange.com/questions/4338/correctly-scaling-a-tikzpicture:
      \begin{tikzpicture}
        \node (A) {
ar tai ``A''?
        };
        \node (B) [below left = of A] {``A'' ($p = 0.75$)};
        \node (C) [below right = of A] {
ar tai ``1''?
        };
        \node (D) [below left = of C, xshift = +1cm] {
tai skaitmuo?
        };
        \node (E) [below right = of C, xshift = -1cm] {``1'' ($p = 0.15$)};
        \node (d1) [below left = of D, xshift = +1cm] {``B'' ($p = 0.05$)};
        \node (d2) [below right = of D, xshift = -1cm] {``2'' ($p = 0.05$)};

        \draw [->,thick] (node cs: name=A) -- (node cs: name=B)
        node [near start, anchor = east] {
          \scriptsize
          \parbox{2cm}{
            \begin{center}
Taip

              $p_c = 0.75$
            \end{center}
          }
        };

        \draw [->,thick] (node cs: name=A) -- (node cs: name=C)
        node [near start, anchor = west, xshift = 0.3cm] {
          \scriptsize
          \parbox{2cm}{
            \begin{center}
Ne

              $p_c = 0.25$
            \end{center}
          }
        };

        \draw [->,thick] (node cs: name=C) -- (node cs: name=D)
        node [near start, anchor = east] {
          \scriptsize
          \parbox{2cm}{
            \begin{center}
Ne

              $p_c = 0.4$
            \end{center}
          }
        };
        \draw [->,thick] (node cs: name=C) -- (node cs: name=E)
        node [near start, anchor = west] {
          \scriptsize
          \parbox{2cm}{
            \begin{center}
Taip

              $p_c = 0.6$
            \end{center}
          }
        };

        \draw [->,thick] (node cs: name=D) -- (node cs: name=d1)
        node [near start, anchor = east] {
          \scriptsize
          \parbox{2cm}{
            \begin{center}
Ne

              $p_c = 0.5$
            \end{center}
          }
        };
        
        \draw [->,thick] (node cs: name=D) -- (node cs: name=d2)
        node [near start, anchor = west] {
          \scriptsize
          \parbox{2cm}{
            \begin{center}
Taip

              $p_c = 0.5$
            \end{center}
          }
        };

      \end{tikzpicture}
    }
  \end{center}

  \footnotesize
  \visible<2->{
Esant vienodoms tikimybėms:
    $n_{\mathrm{q}} = \log_2 N_{\mathrm{s}} = \log_2
    \frac{1}{p_{\mathrm{s}}} = - \log_2 p_{\mathrm{s}} =
    \log_2 4 = \mathbf{2}$
  }

  \visible<3->{
Pavaizduotiems klausimams (Hafmano kodas):
    $n_{\mathrm{q}} = 0.75 + 2 \times 0.15 + 2 \times 3 \times 0.05 = \mathbf{1.35}$
  }

  \visible<4>{
Teorinė riba:
    $n_{\mathrm{q}} = - \sum_{i=1}^{4} p_i \log_2 p_i = \mathbf{1.15}$
  }
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Bitai ir baitai. Informacijos kiekis}

  \renewcommand{\arraystretch}{1.5}
  %%BEGIN LANGUAGE lt
  Tarkime, kad yra šaltinis, siunčiantis pranešimus iš aibės
  %%END LANGUAGE lt
  $S = \{ M_1, \dots, M_n \}, \; n \in \mathbb{N}$.

Tada:
  $$
  \begin{array}{l}
    S = \{ M_1, \dots, M_n \} \\
    p_i = Pr(M_i), \;\; i = 1\dots n\\
    I_{M_i} = - \log p_i \\
    H = - \displaystyle\sum_{i=1}^{n} p_i \log p_i\\    
  \end{array}
  $$

  \renewcommand{\arraystretch}{1}
Čia:
  $$
  \begin{array}{lll}
    Pr(M_i) & \text{--} & \text{
pranešimo $M_i$ tikimybė;
    }\\
    I_{M_i} & \text{--} & \text{
informacijos kiekis pranešime $M_i$;
    }
    \\
    H & \text{--} & \text{
      \parbox[t]{0.8\textwidth}{
        %%BEGIN LANGUAGE lt
        šaltinio entropija, arba vidutinis informacijos kiekis
        pranešime;
        %%END LANGUAGE lt
      }
    }
    \\
  \end{array}
  $$
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Dviejų lygių signalas $\neq$ 1 bitas}

  \only<1-2>{
    \begin{center}
Dviejų linijų vieno bito atvaizdavimas:
    \end{center}
  }
  
  \only<3-4>{
    \begin{center}
      \begin{tabular}{cc}
        \scriptsize
        \begin{minipage}[b]{4cm}
          $$
          \overbrace{\rule{2cm}{0pt}}^{
            \begin{aligned}
              Pr(\text{"0"}) &=  Pr(\text{"1"}) = 0.5 \\
              H &=  - 2 \cdot 0.5 \cdot \log_2 0.5 \\
              &= - 2 \cdot (-0.5) \\
              &= \mathbf{1} \; \text{\bf
bitas/pranešimui
              } \\
            \end{aligned}
          }
          $$
        \end{minipage}
        &
        \scriptsize
        \begin{minipage}[b]{4.5cm}
          $$
          \overbrace{\rule{4cm}{0pt}}^{
            \begin{aligned}
              Pr(\text{"01"}) =&  Pr(\text{"10"}) = 0.5 \\
              Pr(\text{"00"}) =&  Pr(\text{"11"}) = 0 \\
              H =&- Pr(\text{"01"}) \cdot \log_2 Pr(\text{"01"}) \\
                 &- Pr(\text{"10"}) \cdot \log_2 Pr(\text{"10"}) \\
                 &- \displaystyle\lim_{Pr(\text{"00"})\rightarrow0} Pr(\text{"00"}) \cdot \log_2 Pr(\text{"00"}) \\
                 &- \displaystyle\lim_{Pr(\text{"11"})\rightarrow0} Pr(\text{"11"}) \cdot \log_2 Pr(\text{"11"}) \\
                =&-2 \cdot 0.5 \cdot (-1) \\
                =& \mathbf{1} \;\text{\bf
bitas/pranešimui
              } \\
            \end{aligned}
          }
          $$
        \end{minipage}
      \end{tabular}
    \end{center}
  }

  \only<3->{
    \vspace{-3\baselineskip}
  }
  \begin{center}
    \parbox[c]{3.5cm}{
      \only<1,3>{
        \includegraphics[width=\linewidth]{drawings/decoders/1-out-of-2-select-1.png}
      }
      \only<2,4>{
        \includegraphics[width=\linewidth]{drawings/decoders/1-out-of-2-select-2.png}
      }
    }
  \end{center}

  \only<5->{
    \begin{center}
Dešifratorius 1-iš-4
    \end{center}
    
    \only<5>{
      \begin{center}
        \includegraphics[height=5cm]{drawings/decoders/1-of-4-decoder-select-1.png}
      \end{center}
    }
    \only<6>{
      \begin{center}
        \includegraphics[height=5cm]{drawings/decoders/1-of-4-decoder-select-2.png}
      \end{center}
    }
    \only<7>{
      \begin{center}
        \includegraphics[height=5cm]{drawings/decoders/1-of-4-decoder-select-3.png}
      \end{center}
    }
    \only<8>{
      \begin{center}
        \includegraphics[height=5cm]{drawings/decoders/1-of-4-decoder-select-4.png}
      \end{center}
    }
  }
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Pussumatoris}

  \begin{center}
    \begin{tabular}{rr|rr}
      \multicolumn{4}{c}{
Sudėtis:
      } \\
      \multicolumn{4}{c}{$ A + B $} \\
      & \multicolumn{1}{l}{} & \multicolumn{2}{c}{B} \\
      & $+$ &  0 & 1 \\
      \cline{2-4}
      \multirow{2}{*}{A}
      & 0   &  0 & 1 \\  
      & 1   &  1 & \textcolor{TwoToNthColor}{1}0 \\  
    \end{tabular}
    \hspace{2em}
    \begin{tabular}{cc|c}
      \multicolumn{3}{c}{
Suma:
      }\\
      \textbf{A} & \textbf{B} & \textbf{S} \\
      \hline
      0 & 0 & 0 \\
      0 & 1 & 1 \\
      1 & 0 & 1 \\
      1 & 1 & 0 \\
    \end{tabular}
    \hspace{2em}
    \begin{tabular}{cc|c}
      \multicolumn{3}{c}{
Perkėlimas:
      }\\
      \textbf{A} & \textbf{B} & \textbf{C} \\
      \hline
      0 & 0 & 0 \\
      0 & 1 & 0 \\
      1 & 0 & 0 \\
      1 & 1 & \textcolor{TwoToNthColor}{1} \\
    \end{tabular}
  \end{center}

  \begin{center}
    \parbox{2em}{
      \only<2->{
        \bf
        \begin{tabular}{r}
          A \\
          \\
          B\\
          \\
          \\
        \end{tabular}
      }
    }
    %
    \parbox{4cm}{
      \only<2>{
        \includegraphics[width=\linewidth]{drawings/adders/half-adder-A0-B0.png}
      }
      \only<3>{
        \includegraphics[width=\linewidth]{drawings/adders/half-adder-A1-B0.png}
      }
      \only<4>{
        \includegraphics[width=\linewidth]{drawings/adders/half-adder-A0-B1.png}
      }
      \only<5>{
        \includegraphics[width=\linewidth]{drawings/adders/half-adder-A1-B1.png}
      }
    }
    %
    \parbox{2em}{
      \only<2->{
        \bf
        \begin{tabular}{l}
          S \\
          \\
          \\
          C\\
          \\
        \end{tabular}
      }
    }
  \end{center}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Pilnas sumatorius}

  \small
  \begin{center}
    \begin{tabular}{ccc|c}
      \multicolumn{4}{c}{
Suma:
      }\\
      \textbf{C$_\text{in}$} & \textbf{A} & \textbf{B} & \textbf{S} \\
      \hline
      0 & 0 & 0 & 0 \\
      0 & 0 & 1 & 1 \\
      0 & 1 & 0 & 1 \\
      0 & 1 & 1 & 0 \\
      \hline
      1 & 0 & 0 & 1 \\
      1 & 0 & 1 & 0 \\
      1 & 1 & 0 & 0 \\
      1 & 1 & 1 & 1 \\
    \end{tabular}
    \hspace{2em}
    \begin{tabular}{ccc|ccc}
      \multicolumn{4}{c}{
Perkėlimas:
      }\\
      \textbf{C$_\text{in}$} & \textbf{A} & \textbf{B} & \textbf{C$_\text{out}$} \\
      \hline
      0 & 0 & 0 & 0 \\
      0 & 0 & 1 & 0 \\
      0 & 1 & 0 & 0 \\
      0 & 1 & 1 & \textcolor{TwoToNthColor}{1} & $\overline{C_{in}}AB$ & $AB$ \\
      \hline
      1 & 0 & 0 & 0 \\
      1 & 0 & 1 & \textcolor{TwoToNthColor}{1} & $C_{in}\overline{A}B$ & $C_{in}B$ \\
      1 & 1 & 0 & \textcolor{TwoToNthColor}{1} & $C_{in}A\overline{B}$ & $C_{in}A$ \\
      1 & 1 & 1 & \textcolor{TwoToNthColor}{1} & $C_{in}AB$ \\
    \end{tabular}
  \end{center}

  \begin{center}
    \parbox[c]{4cm}{
      \includegraphics[width=\linewidth]{drawings/adders/full-adder-sum-A0-B0.png}
    }
    \parbox[c]{4.5cm}{
      \includegraphics[width=\linewidth]{drawings/adders/full-adder-carry-compact-A0-B0-C0.png}
    }
  \end{center}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Pilnas sumatorius (naivi realizacija)}

  \hfill
  \begin{minipage}{0.3\textwidth}
    \scriptsize
    \begin{tabular}{ccc|cc}
      \multicolumn{5}{c}{
Suma ir perkėlimas:
      }\\
      \textbf{C$_\text{in}$} & \textbf{A} & \textbf{B} & \textbf{C$_\text{out}$} & \textbf{S} \\
      \hline
      \only<1>{\bf} 0 & \only<1>{\bf} 0 & \only<1>{\bf} 0 & \only<1>{\bf} 0 & \only<1>{\bf} 0 \\
      \only<3>{\bf} 0 & \only<3>{\bf} 0 & \only<3>{\bf} 1 & \only<3>{\bf} 0 & \only<3>{\bf} 1 \\
      {} 0 & {} 1 & {} 0 & {}                           0  & {} 1 \\
      {} 0 & {} 1 & {} 1 & {} \textcolor{TwoToNthColor}{1} & {} 0 \\
      \hline
      \only<2>{\bf} 1 & \only<2>{\bf} 0 & \only<2>{\bf} 0 & \only<2>{\bf} 0                            & \only<2>{\bf} 1 \\
      \only<4>{\bf} 1 & \only<4>{\bf} 0 & \only<4>{\bf} 1 & \only<4>{\bf} \textcolor{TwoToNthColor}{1} & \only<4>{\bf} 0 \\
      {} 1 & {} 1 & {} 0 & {} \textcolor{TwoToNthColor}{1} & {} 0 \\
      \only<5>{\bf} 1 & \only<5>{\bf} 1 & \only<5>{\bf} 1 & \only<5>{\bf} \textcolor{TwoToNthColor}{1} & \only<5>{\bf} 1 \\
    \end{tabular}
  \end{minipage}
  \hfill
  \begin{minipage}[t]{2em}
    \scriptsize
    \begin{tabular}{r}
      \\
      \textbf{C$_\text{in}$} \\
      \\
      \bf A \\
      \\
      \bf B \\
      \\
      \\
      \\
      \\
      \\
      \\
      \\
      \\
      \\
    \end{tabular}
  \end{minipage}
  \begin{minipage}[t]{0.4\textwidth}
    \begin{center}
      \parbox{4cm}{
        \only<1>{
          \includegraphics[width=\linewidth]{drawings/adders/full-adder-naive-A0-B0-C0.png}
        }
        \only<2>{
          \includegraphics[width=\linewidth]{drawings/adders/full-adder-naive-A1-B0-C0.png}
        }
        \only<3>{
          \includegraphics[width=\linewidth]{drawings/adders/full-adder-naive-A0-B1-C0.png}
        }
        \only<4>{
          \includegraphics[width=\linewidth]{drawings/adders/full-adder-naive-A1-B1-C0.png}
        }
        \only<5>{
          \includegraphics[width=\linewidth]{drawings/adders/full-adder-naive-A1-B1-C1.png}
        }
      }
    \end{center}
  \end{minipage}
  \begin{minipage}[t]{2em}
    \scriptsize
    \begin{tabular}{l}
      \bf S \\
      \\
      \\
      \\
      \\
      \\
      \\
      \textbf{C$_\text{out}$} \\
      \\
      \\
      \\
    \end{tabular}
  \end{minipage}
  \hfill
  \mbox{}
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Pilnas sumatorius}

  \begin{center}
    \parbox[c]{4cm}{
      \includegraphics[width=\linewidth]{drawings/adders/full-adder-naive-A0-B0-C0.png}
    }
    \hspace{2em}
    \parbox[c]{5cm}{
      \includegraphics[width=\linewidth]{drawings/adders/full-adder-A0-B0-C0.png}
    }
  \end{center}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Pilno sumatoriaus simboliai}

  \begin{center}
    \parbox[c]{3cm}{
      \begin{center}
        \includegraphics[width=0.8\linewidth]{drawings/adders/adder-symbol.eps}

        \vspace{\baselineskip}
        \includegraphics[width=0.7\linewidth]{drawings/adders/adder-symbol-logisim-A0-B0-C0.png}
      \end{center}
    }
    \hspace{2em}
    \parbox[c]{5cm}{
      \includegraphics[width=\linewidth]{drawings/adders/full-adder-A0-B0-C0.png}
    }
  \end{center}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{4 bitų sumatorius}

  \begin{center}
    \hfill
    $ 0101_2 + 1110_2 = \textcolor{TwoToNthColor}{1}\,0011_2 $\hfill
    $ 5_{16} + \mathrm{E}_{16} = \textcolor{TwoToNthColor}{1}3_{16} $\hfill
    $ 5_{10} + 14_{10} = 19_{10} $\hfill\mbox{}

    \vspace{\baselineskip}
    \hfill
    \parbox[c]{3.5cm}{
      \includegraphics[width=\linewidth]{drawings/adders/full-adder-component-5+E.png}
    }
    \hfill
    \parbox[c]{3.5cm}{
      \includegraphics[width=\linewidth]{drawings/adders/full-adder-4-bit-logisim-5+E.png}
    }
    \hfill
    \mbox{}
  \end{center}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Vienos skilties daugintuvas}

  \only<1>{
    \begin{center}
      \parbox[c]{6cm}{
        \includegraphics[width=\linewidth]{drawings/multipliers/operand-times-single-digit-0.png}
      }
    \end{center}
  }
  \only<2>{
    \begin{center}    
      \parbox[c]{6cm}{
        \includegraphics[width=\linewidth]{drawings/multipliers/operand-times-single-digit-1.png}
      }
    \end{center}
  }
  \only<1>{
    \begin{center}
      \parbox[c]{4cm}{
        \includegraphics[width=\linewidth]{drawings/multipliers/mult-block-times-single-digit-0.png}
      }
    \end{center}
  }
  \only<2>{
    \begin{center}    
      \parbox[c]{4cm}{
        \includegraphics[width=\linewidth]{drawings/multipliers/mult-block-times-single-digit-1.png}
      }
    \end{center}
  }

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{4 bitų daugintuvas}

  \begin{center}
    \hfill
    \only<1>{
      $ 1101_2 \times 0101_2 = 0100\,0001_2 $\hfill
      $ \mathrm{D}_{16} \times 5_{16} = 41_{16} $\hfill
      $ 13_{10} \times 5_{10} = 65_{10} $\hfill\mbox{}
    }
   \only<2>{
      $ 1111_2 \times 1100_2 = 1011\,0100_2 $\hfill
      $ \mathrm{F}_{16} \times \textrm{C}_{16} = \mathrm{B}4_{16} $\hfill
      $ 15_{10} \times 12_{10} = 180_{10} $\hfill\mbox{}
    }

    \vspace{0.5\baselineskip}
    \parbox[c]{12cm}{
      \only<1>{
        \includegraphics[width=\linewidth]{drawings/multipliers/simple-multiplier-Dx5.png}
      }
      \only<2>{
        \includegraphics[width=\linewidth]{drawings/multipliers/simple-multiplier-FxC.png}
      }
    }
  \end{center}

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Atimtis}

Atimti mažesnį iš didesnio lengva:
  $$
  \renewcommand{\arraystretch}{1.7}
  \begin{array}{c}
    1101_2 - 100_2 = 1001_2 \\

    1101_2 - 11_2 =
    1\overset{\textcolor{TwoToNthColor}{1}}{1}\textcolor{TwoToNthColor}{0}1_2 - 11_2
    = 1010_2 \\

    10_2 - 11_2 = \text{???}
  \end{array}
  $$

O kas bus, jei sudėsime?

  \begin{center}
    \begin{tabular}{llllll}
      \multirow{2}{*}{$+$}
      &  & 0 & 0 & 0 & 1 \\
      &  & 1 & 1 & 1 & 1 \\
      \hline
      & \textcolor{gray}{1} & 0 & 0 & 0 & 0 \\
    \end{tabular}
  \end{center}

\end{frame}

%------------------------------------------------------------------------------

\definecolor{verylightgray}{rgb}{0.9, 0.9, 0.9}

\begin{frame}
\frametitle{Neigiam skaičiai}

Sudėkime didelius skaičius, kad atsirastų perkėlimas:
  
  \begin{center}
    \begin{tabular}{llllll}
      \multirow{2}{*}{$+$}
      &  & 0 & 0 & 0 & 1 \\
      &  & 1 & 1 & 1 & 1 \\
      \hline
      & \textcolor{verylightgray}{1} & 0 & 0 & 0 & 0 \\
    \end{tabular}
  \end{center}

  i.e.:
  $$
  1111_2 + 1_2 = 0_2
  $$

bet mes žinome, kad
  $$
  (-1) + 1 = 0
  $$

Ar galime pasakyti, kad
  $ 1111_2 = -1_2 $
tam tikra prasme?
  
\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Papildinys iki dviejų}

Pridėti $1111$ reiškia:
  $ 1111_2 = \textcolor{TwosComplementColor}{1\,0000_2 - 1} = 2^4 - 1 $
  
  \vspace{\baselineskip}
Ignoruoti perkėlimo bitą – reiškia atimti
  \textcolor{TwoToNthColor}{$ 1\,0000_2 = 2^4 $}

  \vspace{\baselineskip}
Taigi
  $$
  {
    \begin{aligned}
      1 + \textcolor{TwosComplementColor}{1111_2} \; \text{\textcolor{TwoToNthColor}{
        \footnotesize
(ignoruojant perkėlimą)
      }}
      &= 1 + (\textcolor{TwosComplementColor}{1\,0000_2 - 1}) - \textcolor{TwoToNthColor}{1\,0000_2} \\
      &= 1 - 1 \\
      &= 0 \\
    \end{aligned}
  }
  $$
  
Patikrinkime – metodas veikia bet kokiam N bitų skaičiui:
  $$
  a + \underbrace{(\textcolor{TwosComplementColor}{2^N - b})}_{\text{
$b$ papildomasis kodas
  }} - \;\textcolor{TwoToNthColor}{2^N} = a - b
  $$

\end{frame}

%------------------------------------------------------------------------------

\begin{frame}
\frametitle{Apibendrinimas}

  \begin{itemize}
  \item
    %%BEGIN LANGUAGE lt
    Natūrali skaitmeninių kompiuterių skaičiavimo sistema –
    dvejetainė; yra paprasti algoritmai paversti skaičius į dvejetainę
    ir iš jos į kitas skaičiavimo sistemas, bet sistemos pagrindais 8 ir
    16 yra pačios patogiausios.
    %%END LANGUAGE lt
  \item
    %%BEGIN LANGUAGE lt
    Perlo programavimo kalba galima lengvai paversti skaičius iš vienos
    sistemos į kitą;
    %%END LANGUAGE lt
  \item
    %%BEGIN LANGUAGE lt
    Ne kiekvieną skaičių galime paversti į kitą sistemą tiksliai!
    %%END LANGUAGE lt
  \item
    %%BEGIN LANGUAGE lt
    Ne visada signalas su dviem būsenom perduoda 1 bitą informacijos!
    %%END LANGUAGE lt
  \item
    %%BEGIN LANGUAGE lt
    Galime sukonstruoti logines grandines, kurios atlieka dvejetainę
    aritmetiką (sudėtį, atimtį, daugybą ir t.t.);
    %%END LANGUAGE lt
  \end{itemize}
  
\end{frame}

%------------------------------------------------------------------------------

%% \begin{frame}
%%   %%LANGUAGE en \frametitle{Ternary logic gate}
%%   %%LANGUAGE lt \frametitle{Trejetainis loginis ventilis}
%%   %%LANGUAGE ru \frametitle{Троичный логический вентиль}
%% 
%%   
%% \end{frame}

%------------------------------------------------------------------------------

\begin{frame}[allowframebreaks]
\frametitle{Šaltiniai}

  \renewcommand{\bibfont}{\scriptsize}
  \printbibliography

\end{frame}

%------------------------------------------------------------------------------

\end{document}
% 2023-09-11 08:52:35 EEST
