#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <sys/timeb.h>
#include <math.h>
#include <string.h>
// ----------------------------------------------

typedef char strT[80];
#include "sj-01.h"
#include "sj-02.h"
#include "sj-03.h"

// toBin(a, s1);
void toBin(int no, strT s1)
{
	strT s2;
	int ct, a, b;
	strcpy(s2, "00000000");
	ct=8;
	
	do {
		a= no/2;
		b= no%2;
		s2[--ct]= b + '0';
		no= a;
	} while (a>0);
	
	strcpy(s1, s2);
}

// toDec(s1, &c);
void toDec(strT s1, int *n)
{
	int a= 0, b, i;
	// printf("s1= %s \n", s1);
	
	b= 1;
	for (i=7;i>=0;i--) {
		if (s1[i]=='1') {
			a+= b;
			// printf("* ");
		}
		b*= 2;
	}
	*n= a;
}


// ----------------------------------------------

int main()
{
	strT s1, s2;
	int t1, a, b, c, d, e;
	
	time1(&t1);
	rnd1(&t1);
	a= t1%256;// 0 - 255
	b= a;
	
	d= a%16;
	e= a>>4;
	
	toBin(b, s1);
	printf("e= %d, d= %d \n", e, d);
	
	printf("a= %3d, s1= (%s) \n", a, s1);
	
	toDec(s1, &c);
	printf("c= %d \n", c);
	
	
	return 0;
}// end of main()

