ravesli/lesson_47/main.cpp

28 lines
531 B
C++
Raw Normal View History

2021-09-07 14:10:24 +00:00
/*
* main.cpp
*
* Created on: 7 сент. 2021 г.
* Author: alexander
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
2021-09-07 14:21:20 +00:00
cout << "Введите число от 0 до 255: ";
int n;
cin >> n;
cout << "Число " << n << " в двоичной системе счисления: ";
2021-09-07 14:10:24 +00:00
2021-09-07 14:21:20 +00:00
for (int i = 7; i >= 0; --i) {
int degree = pow(2, i);
cout << (n >= degree) << (i == 4 ? " " : "");
if (degree <= n)
n -= degree;
}
2021-09-07 14:10:24 +00:00
2021-09-07 14:21:20 +00:00
return 0;
2021-09-07 14:10:24 +00:00
}