Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by dad ( 6 years ago )
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

struct taptin
{
	short khac;
	int nguon1, nguon2, nguon3, nguon4;
	int dich1, dich2, dich3, dich4;
	char text[65535];
};

struct taptin nhap()
{
	struct taptin no1;
	
	printf("Nhap thong tin goi tin PC1 :\n");
	no1.khac = 16535;
//	no1.khac[0] = 1;
//	no1.khac[1] = 6;
//	no1.khac[2] = 5;
//	no1.khac[3] = 3;
//	no1.khac[4] = 5;
	no1.nguon1 = 192;
	no1.nguon2 = 168;
	no1.nguon3 = 1;
	no1.nguon4 = 100;
	
	no1.dich1 = 200;
	no1.dich2 = 169;
	no1.dich3 = 2;
	no1.dich4 = 101;
	
	strncpy(no1.text,"Toi rat thich hoc lap trinh! Con ban thi sao? Hoc ky nay toi se co gang dat diem 10.",65535);
	
	return no1;
}

void xuat(struct taptin eg)
{
	//printf("\n%08d\n", eg.khac);
		
	printf("%08d.%08d.%08d.%08d\n", eg.nguon1, eg.nguon2, eg.nguon3, eg.nguon4);
	
	printf("%08d.%08d.%08d.%08d\n", eg.dich1, eg.dich2, eg.dich3, eg.dich4);
	
	printf("%s\n", eg.text);
}

void tsn(short dec)
{
	int i = 0;
	short z[16];
	
	int binumber = 0;
	while(binumber < 16)
	{
		z[16*(i+1)-1-binumber] = dec % 2;
		dec /= 2;
 		binumber = binumber + 1;
	}
	
	for(i=0;i<16;i++)
		printf("%d", z[i]);
}

int NST(int binumber)
{
	int dec = 0;
	int i = 0;
	while(binumber>0)
	{
		dec += (binumber % 10) * pow(2, i);
		i++;
		binumber /= 10;
	}
	return dec;
}



int TSN(int dec)
{
	int i = 0;
	int z[8];
	
	int binumber = 0;
	while(binumber < 8)
	{
		z[8*(i+1)-1-binumber] = dec % 2;
		dec /= 2;
 		binumber = binumber + 1;
	}
	
	int k = 0;
	for (i = 0; i < 8; i++)
    k = 10 * k + z[i];
    return k;
}

int main()
{
	struct taptin no1, no2, temp;
	int i;
	
	no1 = nhap();
	
	//for(i=0;i<5;i++)
		printf("%d", no1.khac);
	printf("\n");
		
	printf("%d.%d.%d.%d\n", no1.nguon1, no1.nguon2, no1.nguon3, no1.nguon4);

	printf("%d.%d.%d.%d\n", no1.dich1, no1.dich2, no1.dich3, no1.dich4);
	
	printf("%s\n", no1.text);
	printf("\n");
	
	
	no2.nguon1 = TSN(no1.nguon1);
	no2.nguon2 = TSN(no1.nguon2);
	no2.nguon3 = TSN(no1.nguon3);
	no2.nguon4 = TSN(no1.nguon4);
	
	no2.dich1 = TSN(no1.dich1);
	no2.dich2 = TSN(no1.dich2);
	no2.dich3 = TSN(no1.dich3);
	no2.dich4 = TSN(no1.dich4);
	strcpy(no2.text,no1.text);
	
	printf("Sau khi doi sang thap phan :\n");
	tsn(no1.khac);
	printf("\n");
	xuat(no2);
	
	printf("\nTong do dai goi tin : %d bytes\n", 96 + sizeof(char)*8*strlen(no1.text));
	
	printf("\nThoi gian goi tin chuyen tu PC1 den PC2 ( Tuyen 2 ) : %f s\n", (float) (96 + sizeof(char)*8*strlen(no1.text)) / (64*1000));
	
	printf("\nDia chi nguon trong goi tin PC2 nhan duoc theo dinh dang nhi phan : \n");
	
	no1.nguon1 = 92;
	no1.nguon4 = 101;
	no2.nguon1 = TSN(no1.nguon1);
	no2.nguon4 = TSN(no1.nguon4);
	
	printf("%08d.%08d.%08d.%08d\n", no2.nguon1, no2.nguon2, no2.nguon3, no2.nguon4);
	
	no2.nguon1 = NST(no2.nguon1);
	no2.nguon2 = NST(no2.nguon2);
	no2.nguon3 = NST(no2.nguon3);
	no2.nguon4 = NST(no2.nguon4);
	
	printf("\nDia chi nguon trong goi tin PC2 nhan duoc theo dinh dang thap phan : \n");
	
	printf("%d.%d.%d.%d\n", no2.nguon1, no2.nguon2, no2.nguon3, no2.nguon4);
	
	return 0;
}

 

Revise this Paste

Your Name: Code Language: