Check out this line:
5 div 2 = 4
It equals 2, not 4.
You also have a typo here:
22 mod 2 = 1, x = "0"
سؤال
decimal 45 is 101101 in binary, when I have to explain the code I get to 1011001, but program outputs the right answer. Where does this 0 go 10110 0 1 after 2 mod 2 = 0?
I followed the steps in program if I type 45 as decimal number:
How it still outputs 101101?!
write('Enter decimal number: ');
readln(dec);
repeat
if (dec mod 2 = 0) then x:= '0'
else x:= '1';
bin:= bin + x;
dec:= dec div 2;
until dec= 0;
writeln(bin);
المحلول
Check out this line:
5 div 2 = 4
It equals 2, not 4.
You also have a typo here:
22 mod 2 = 1, x = "0"