Exercise 1.2 Solutions

1b

10000 - (∑_(k = 1)^80000) 0.125

2d

binarytodecimalinteger[
        num_] := 
Module[{ids, 
          mults}, 
ids = 
          IntegerDigits[
            num]; 
If[(Union[ids] == {0, 1} || 
              Union[ids] == {0} || Union[ids] == {1}), , 
          Print["Not a Binary"]; Break[]]; 
mults = 
          Table[2^(k - 1), {k, Length[ids], 
              1, -1}]; 
Apply[Plus, 
          ids mults]
]

binarytodecimalinteger[1000000111]

2^^1000000111

3c

binarytodecimalfraction[
        num_] := 
Module[{ids, mults, 
          setoff}, 
ids = 
          RealDigits[num]; 
setoff = 
          ids[[2]]; 
If[(Union[ids[[1]]] == {0, 
                  1} || Union[ids[[1]]] == {0} || 
              Union[ids[[1]]] == {1}), , Print["Not a Binary"]; 
          Break[]]; 
mults = 
          Table[(1/2)^k, {k, 1 - setoff, 
              Length[ids[[1]]] - setoff}]; 
N[
          Apply[Plus, ids[[1]] mults]]
]

binarytodecimalfraction[ .1010101]

2^^.1010101

4d

binarytodecimalfraction[11.0010010001]

2^^11.0010010001

5a

(Sqrt[2]) - binarytodecimalfraction[1.0110101]

(Sqrt[2]) - 2^^1.0110101

6d

base10tobinary[
        num_] := 
Module[{bindigits, 
          newnum}, 
bindigits = {}; 
newnum = num; 
While[newnum > 0, 
          PrependTo[bindigits, Mod[newnum, 2]]; 
          newnum = 
            Quotient[newnum, 
              2]]; 
bindigits
]

base10tobinary[2388]

BaseForm[2388, 2]

7d

base10fractobinaryfrac[num_, 
        nbindigitsrightofdecimal_] := 
Module[{bindigits, 
          newnum}, 
bindigits = {}; 
newnum = 2  num; 
Do[
          PrependTo[bindigits, IntegerPart[newnum]]; 
          newnum = 
            2 FractionalPart[
                newnum], {nbindigitsrightofdecimal}]; 
Reverse[bindigits]
]

75/128

N[75/128]

base10fractobinaryfrac[75/128, 7]

BaseForm[N[75/128], 2]

8c

base10fractobinaryfrac[N[1/7], 30]

BaseForm[N[1/7], 2]

9b

N[1/7] - 2^^0.0010010

11

Table[3/(16^k), {k, 1, 5}]

(∑_(k = 1)^∞) (3/(16^k))

13a

14c

base10to[decnum_, 
        newbase_] := 
Module[{newdigits, 
          newnum}, 
newdigits = {}; 
newnum = decnum; 
While[newnum > 0, 
          PrependTo[newdigits, Mod[newnum, newbase]]; 
          newnum = 
            Quotient[newnum, 
              newbase]]; 
newdigits
]

base10to[421, 3]

16c

base10to[721, 5]