SHOW:
|
|
- or go back to the newest paste.
1 | #include <stdio.h> | |
2 | - | #include "stdafx.h" |
2 | + | #include <stdint.h> |
3 | - | #define MAX_BIT_COUNT 32; |
3 | + | #include <stdbool.h> |
4 | ||
5 | - | int _tmain(int argc, _TCHAR* argv[]) |
5 | + | int main(int argc, char* argv[]) |
6 | { | |
7 | - | int numberInput = 0; |
7 | + | int32_t numberInput = 0; |
8 | - | long numberMask = (1 << 31); //43690% |
8 | + | uint32_t numberMask = (1 << 31); //43690% |
9 | - | short numberFinal = 0; |
9 | + | uint32_t numberFinal = 0; |
10 | - | char capture[4]; |
10 | + | |
11 | - | int ind; |
11 | + | while (true) |
12 | - | int active = 1; |
12 | + | { |
13 | numberMask = (1U << 31); | |
14 | - | while (active == 1) |
14 | + | printf("Please enter a number to translate into binary\nTo Exit please type the number 9999\n"); |
15 | - | { |
15 | + | scanf("%d", &numberInput); |
16 | - | numberMask = 0x80000000; |
16 | + | numberFinal = (uint32_t)numberInput; |
17 | - | printf("Please enter a number to translate into binary\nTo Exit please type the number 9999\n"); |
17 | + | |
18 | - | scanf_s("%d", &numberInput); |
18 | + | if (numberFinal == 9999) |
19 | - | getchar(); |
19 | + | { |
20 | - | numberFinal = (short)numberInput; |
20 | + | break; |
21 | - | |
21 | + | } |
22 | - | if (numberFinal == 9999) |
22 | + | else |
23 | - | { |
23 | + | { |
24 | - | active = 2; |
24 | + | for (int i = 0; i < 32; i++) |
25 | - | } |
25 | + | { |
26 | - | else |
26 | + | bool isOne = (numberMask & numberFinal) != 0; |
27 | - | { |
27 | + | printf("%d", (isOne) ? 1 : 0); |
28 | - | for (int i = 0; i < 32; i++) |
28 | + | numberMask >>= 1; |
29 | - | { |
29 | + | } |
30 | - | short printInt = numberMask & numberFinal; |
30 | + | printf("\n\n"); |
31 | - | printf("%d", (printInt > 0) ? 1 : 0); |
31 | + | } |
32 | - | numberMask >>= 1; |
32 | + | |
33 | - | } |
33 | + | |
34 | - | printf_s("\n\n"); |
34 | + | } |
35 | - | } |
35 | + | |
36 | - | |
36 | + | return 0; |
37 | } |