LoginSignup
0
1

More than 5 years have passed since last update.

LaTeXでn進数から10進数への変換式

Posted at

n進数から10進数への変換式をlatexで作成.

test.tex
\documentclass{article}

\usepackage{xstring}
\usepackage{xifthen}
\usepackage{pgf}

\usepackage{amsmath} % align

\begin{document}

\newcounter{ep}
\newcounter{index}

\newcommand{\toD}[2][2]{
   \StrLen{#2}[\mystrlen]
   \setcounter{ep}{\mystrlen}
   \setcounter{index}{0}%
   \whiledo{\value{index} < \mystrlen}{%
      \addtocounter{ep}{-1}
      \stepcounter{index}%
      \StrChar{#2}{\theindex} \times #1^\theep
      \ifnum\theep>0{{}+{}}\fi
   }
}
\newcommand{\toDD}[2][2]{
   \StrLen{#2}[\mystrlen]
   \setcounter{ep}{\mystrlen}
   \setcounter{index}{0}%
   \whiledo{\value{index} < \mystrlen}{%
      \addtocounter{ep}{-1}
      \stepcounter{index}%
      \StrChar{#2}{\theindex} \times 
      \pgfmathint{#1^\theep}\pgfmathresult
      \ifnum\theep>0{{}+{}}\fi
   }
}

\begin{align}
(0334)_8 &= \toD[8]{0334} \\
         &= \toDD[8]{0334} \\
%
(1011011)_2 &= \toD{1011011} \\
            &= \toDD{1011011}
\end{align}

\end{document}

こうなります.

スクリーンショット 2016-12-11 22.56.46.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1