-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexeB.cpp
More file actions
46 lines (35 loc) · 989 Bytes
/
exeB.cpp
File metadata and controls
46 lines (35 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream> // ou iostream.h
#include <iomanip> // usando os manipuladores
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
using namespace std; //mascara anexa cout ou cin
int main(){
// exemplo de um número em decimal
int num;
int i = 0, j;
cout<< "Infome o numero Decimal para tranformar em binario: ";
cin>> num;
// vetor de 8 posições
int vetor_binario[9];
// aux_num serve para guardar num para mostrar posteriormente
int aux_num = num;
// enquanto "num" for maior que 0
while(num > 0)
{
// obtém o resto da divisão de num por 2
vetor_binario[i] = num % 2;
i++;
num = num / 2;
}
printf("%d em binario: ", aux_num);
// percorre o vetor para mostrar o número em binário
for(j = i - 1; j >= 0; j--)
printf("%d", vetor_binario[j]);
printf("\n");
if (aux_num > 255){
printf("Desnconsiderar o valor em Binario... ERRO binario, valor Max 255");
}
return 0;
}