// C++ Binary Clock.cpp : Defines the entry point for the console application. // #pragma warning(disable:4786) #include "stdafx.h" #include #include #include #include #include #include #include #include #include using namespace std; int BinaryNum, A, B, i, on=0, C=0, stringtype, binary, deci, other, total, number, type = 0; char Alfa, s, stype, length, Numb, thetime, hr, minute, sec; int p = 23; //Number of digits of binary that intergers will be converted to. int _tmain(int argc, _TCHAR* argv[]) { char BinaryNum[100]; int len; do{ // Intro Screen if (type == 0){ cout << "***** Binary: All in One *****" << endl; cout << "Binary to Interger Conversion [B]" << endl; cout << "Interger to Binary Conversion [I]" << endl; cout << "Binary Clock [C]" << endl; cout << "To Clear Screen [S]" << endl; cout << "Quit [Q]" << endl; cout << "Toggals String Length Display ON = [L]:1 OFF = [L]:0" << endl; cout << "Format Input: [x]:[#######]" << endl; type = 1;} // Comand line in. cout << "-> "; cin.getline(&BinaryNum[0], ' ' ); CAtlString s( _T(BinaryNum) ); CAtlString stype( _T(s.Mid( 0, 1 ))); // Sets if string Length should be displayed if (stype == 'L' || stype == 'l'){ CAtlString Numb(_T(s.Mid( 2, 1 ))); if (Numb == '1'){on = 1;} if (Numb == '0'){on = 0;} } // Makes sure there is a value after the stype. This stops a strlen error. CAtlString length( _T(s.Mid(2,1))); if (length == "" && (stype == 'b' || stype == "B" || stype == 'i' || stype == "I")){printf("You need to include a value!"); cout << endl; stype = "";} if ( stype == 'b' || stype == "B" || stype == 'i' || stype == "I"){ // Returns string length len = strlen( BinaryNum )-2; if (on == 1){ printf( "%s is %d characters long\n", BinaryNum, len ); }} // this Figures out binary to intergers if (stype == "B" || stype == "b"){A=0; total=0; for (;A Decimal [ " << total << " ]" < Binary [ " ; for (;A= 0){ number = number - (pow(2, p))/(pow(2, A)); cout << "1" ;} else{cout << "0" ;} A++;} cout << " ]" << endl;} // Gets time and Converts it to binary. if (stype == "c" || stype == "C"){ time_t rawtime; time ( &rawtime ); CAtlString thetime( _T(ctime (&rawtime)) ); CAtlString hr(_T(thetime.Mid(11, 2))); CAtlString minute(_T(thetime.Mid(14, 2))); CAtlString sec(_T(thetime.Mid(17, 2))); cout << "Decimal Time ["; cout << hr << ":"; cout << minute << ":"; cout << sec << "]" << endl; cout << "Binary Time ["; A=0; number = atoi(hr); for (;A<7+1;){ if (number - ((pow(2, 7))/(pow(2, A))) >= 0){ number = number - (pow(2, 7))/(pow(2, A)); cout << "1" ;} else{cout << "0" ;} A++;} cout << ":" ; A=0; number = atoi(minute); for (;A<7+1;){ if (number - ((pow(2, 7))/(pow(2, A))) >= 0){ number = number - (pow(2, 7))/(pow(2, A)); cout << "1" ;} else{cout << "0" ;} A++;} cout << ":" ; A=0; number = atoi(sec); for (;A<7+1;){ if (number - ((pow(2, 7))/(pow(2, A))) >= 0){ number = number - (pow(2, 7))/(pow(2, A)); cout << "1" ;} else{cout << "0" ;} A++;} cout << "]" << endl; } // clears the screen. if(stype == 's' || stype == 'S'){system("cls");} // quits the program. TODO: find a better way to do this. if(stype == 'q' || stype == 'Q'){break;} // does nothing... but works... I guess you need this for a "do" function. }while(stype != 'q' || stype != 'Q'); return 0; }