{Skriv naturlig tall binært.
Bit'ene skrives ut fra høyre.}

1. Input n	{n er et naturlig tall}
2. Repeat
	2.1. Output n mod 2
	2.2. n <- n div 2
   until n=0

Step	n	Output
1	100
2.1		0
2.2	50
2.1		0
2.2	25
2.1		1
2.2	12
2.1		0
2.2	6
2.1		0
2.2	3
2.1		1
2.2	1
2.1		1
2.2	0
(slutt)

100 = 1100100_2

2	100
	50	0
	25	0
	12	1
	6	0
	3	0
	1	1
	0	1

100 = 1100100_2


{Skriv desimaltall binært.
Stopper ikke alltid.}

1. Input x	{0 <= x < 1 er reell}
2. Repeat
	2.1. y <- 2x
	2.2. Output floor(y)	{heltallsdelen}
	2.3. x <- frac(y)	{desimaldelen}
   until x=0

Step	x	y	Output
1	0,707
2.1		1,414
2.2			1
2.3	0,414
2.1		0,828
2.2			0
2.3	0,828
2.1		1,656
2.2			1
2.3	0,656
2.1		1,312
2.2			1
2.3	0,312
2.1		0,624
2.2			0
2.3	0,624
2.1		1,248
2.2			1
2.3	0,248
2.1		0,496
2.2			0
2.3	0,496
2.1		0,992
2.2			0
2.3	0,992
2.1		1,984
2.2			1
2.3	0,984
(etc)

0,707_10 = 0,101 101 001 ..._2

	707	2
1	414
0	828
1	656
1	312
0	624
1	248
0	496
0	992
1	984
(etc)

0,707_10 = 0,101 101 001 ..._2


{Skriv desimalltall binært, med et gitt antall siffer.}

1. Input x, siffer
2. For i=1 to siffer do
	2.1. y <- 2x
        2.2. Output floor(y)    {heltallsdelen}
        2.3. x <- frac(y)       {desimaldelen}

Step	x	siffer	i	y	Output
1	0,707	3
2			1
2.1				1,414
2.2					1
2.3	0,414
2			2
2.1				0,828
2.2					0
2.3	0,828
2			3
2.1				1,656
2.2					1
2.3	0,656
(slutt) 
