/* ************************************************************************** * Program name : 004_Integer_to_binary_format (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/04 - first version * ************************************************************************** * Description : (a) input a number between 0 to 127 * * (b) display error message if >127 or <0 * * (c) output the value in 8-bits binary format * ************************************************************************** */ #include #include int main() { // part 1 : declaration int Integer1; // part 2 : input cout << "Please enter a number between (0 to 127) : "; cin >> Integer1; cout << "\n"; if (Integer1<0) cout << "Sorry! too small\n\n\a"; else if (Integer1>127) cout << "Sorry! too large\n\n\a"; else { cout << "The number is " << Integer1 << "\n" << "Equals to binary pattern : " << (Integer1 / 64)%2 << (Integer1 / 32)%2 << (Integer1 / 16)%2 << (Integer1 / 8)%2 << (Integer1 / 4)%2 << (Integer1 / 2)%2 << (Integer1 % 2) << "\n\n" << endl; }; system("PAUSE"); return 0; // This is not an assignment statement ; no "=" }