From bc8772a6eed7f274fe559182c58339aeda58ab5f Mon Sep 17 00:00:00 2001 From: Antti H S Laaksonen Date: Tue, 7 Mar 2017 17:54:11 +0200 Subject: [PATCH] Fix bitset example --- chapter04.tex | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/chapter04.tex b/chapter04.tex index dfd25c0..df8450c 100644 --- a/chapter04.tex +++ b/chapter04.tex @@ -479,12 +479,12 @@ For example, the following code creates a bitset that contains 10 elements: \begin{lstlisting} bitset<10> s; -s[2] = 1; -s[5] = 1; -s[6] = 1; -s[8] = 1; -cout << s[4] << "\n"; // 0 -cout << s[5] << "\n"; // 1 +s[1] = 1; +s[3] = 1; +s[4] = 1; +s[7] = 1; +cout << s[4] << "\n"; // 1 +cout << s[5] << "\n"; // 0 \end{lstlisting} The benefit in using bitsets is that @@ -500,11 +500,11 @@ can be efficiently manipulated using bit operators, which makes it possible to optimize algorithms using bit sets. -The following code shows another way to create a bitset: +The following code shows another way to create the above bitset: \begin{lstlisting} -bitset<10> s(string("0010011010")); -cout << s[4] << "\n"; // 0 -cout << s[5] << "\n"; // 1 +bitset<10> s(string("0010011010")); // from right to left +cout << s[4] << "\n"; // 1 +cout << s[5] << "\n"; // 0 \end{lstlisting} The function \texttt{count} returns the number