ltbaogt
Tổng số bài gửi : 18 Join date : 01/01/2010
| Tiêu đề: nhi phan sang thap phan Thu Apr 08, 2010 9:05 am | |
| - Code:
-
// Bin2Dec.cpp : Defines the entry point for the console application. // /*** ** Chuong Trinh doi 32 bit thanh so nguyen ** Chua thuc hien kiem tra day bit nhap. ** Yeu cau sinh vien xu ly neu nhap it hon 32 bit. ** Bit o vi tri so 0 la bit cao nhat ***/ #include "stdafx.h" #include "conio.h" #include "stdio.h" #include "string.h" int Bin2Dec (const char arrBit[]); int _tmain(int argc, _TCHAR* argv[]) { //Test chuong trinh char arrBit[33]; memset((void *)arrBit,0,33); gets(arrBit); int n = Bin2Dec(arrBit); printf ("%d\n",n); return 0; } int Bin2Dec (const char arrBit[]) { int n = 0; for (int i = 0;i<8;i++) n = (n << 1) | (arrBit[i] - 48); return n; } | |
|