Extracting Bits

Example Code Using Java (Console Class)

// The "Bits" class.

import java.awt.*;

import hsa.Console;

public class Bits

{

static Console c; // The output console

public static void main (String[] args)

{

double bit1;

double bit2;

double bit4;

double bit8;

c = new Console ();

for (int n = 0 ; n < 16 ; n++)

{

bit1 = n % Math.pow (2, (0 + 1)) / Math.pow (2, 0);

bit2 = n % Math.pow (2, (1 + 1)) / Math.pow (2, 1);

bit4 = n % Math.pow (2, (2 + 1)) / Math.pow (2, 2);

bit8 = n % Math.pow (2, (3 + 1)) / Math.pow (2, 3);

c.println (n + " " + (int) bit8 + (int) bit4 + (int) bit2 + (int) bit1);

}

} // main method

} // Bits class

Example Code Using Turing

var bit1, bit2, bit4, bit8 : int

for n : 0 .. 15

bit1 := n mod (2 ** (0 + 1)) div (2 ** 0)

bit2 := n mod (2 ** (1 + 1)) div (2 ** 1)

bit4 := n mod (2 ** (2 + 1)) div (2 ** 2)

bit8 := n mod (2 ** (3 + 1)) div (2 ** 3)

put n, ' ', bit8, bit4, bit2, bit1

end for