0
Write program
I want help how to write the programming for this question (To convert 234 into binary number) ???
7 ответов
+ 4
to convert a number to binary you can do it with the mod operator:
234 % 2 = 0 (234/2 = 117)
117 % 2 = 1 (117 / 2 = 58)
58 % 2 = 0
29 % 2 = 1
14 % 2 = 0
7 % 2 = 1
3 % 2 = 1
1 % 2 = 1
Now you have this series:
01010111
Reverse it to get the binary number:
11101010 = 234
* int number = 234
* int array to store the 0's and 1's
* a for loop --> 8 bit --> i from 0 to 7
(highest 8 bit number = 255 = 11111111)
* inside for loop: store number % 2 in your array, then number/=2
* at the end: reverse your array
+ 2
The theory: https://www.google.de/amp/s/m.wikihow.com/Convert-from-Decimal-to-Binary%3famp=1
int n = 234; //your number
int[] binary = new int[8]; //an array
//fill your array
for(int i = 0; i < 8; i++){
binary[i] = n % 2;
n/=2;
}
//binary = [0,1,0,1,0,1,1,1]
//print your array (reverse it)
for(int i = 7; i >=0; i--){
System.out.print(binary[i]);
}
//output: 11101010
+ 2
Azza you can have a look on my code:
https://code.sololearn.com/cs11pc60PQ3g/?ref=app
+ 1
Thank you so much
+ 1
Azza Your welcome.
+ 1
Denise Roßberg I'm really grateful to you
0
Excuse me
can you explain more this question 🥺??
I try to write the programming in Code Blocks but i can't do it .. I'm a novice in programming and I have to solve it and submit it tomorrow!
Denise Roßberg