decimal to binary manually
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Faisal Al-Wazir
el 7 de Mzo. de 2022
Respondida: Walter Roberson
el 8 de Mzo. de 2022
Design a program using a flowchart that prompts the user for a positive integer number smaller than 256 (i.e. [0..255]) and converts it into an 8-bit binary number. The bits are the remainders of the successive divisions of the input number by 2. The first division remainder is the least significant bit (i.e. the right most), and the last division remainder is the most significant bit (i.e. the left most bit). The result should be stored as a string and then printed.
The following is a sample run: Please enter a number between 0 and 255: 83
The binary equivalent of 83 is 01010011
3 comentarios
Jaya
el 8 de Mzo. de 2022
Editada: Jaya
el 8 de Mzo. de 2022
I didn't run this code but doesn't it work, you mean?
Since you asked a question in this forum I assume you need help on the Matlab version of the code you presented. In that case, please can you try rewriting in Matlab and paste here? But if your final requirement is not a Matlab code but rather help on the technical part then you may consider posting this in some Stack exchange type forums. That would be better for your scenario.
Respuesta aceptada
Walter Roberson
el 8 de Mzo. de 2022
n=n/2;
There is an important difference between that operation in C and MATLAB. When n is a positive integer datatype, then n/2 truncates in C. For example in C integer 5/2 truncates to 2. However in MATLAB, the operation rounds so 5/2 would have an intermediate value of 2.5 and that would round to 3.
The way to handle the situation in MATLAB is to convert the values to double, carry out the floating point operation, then floor() the results
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!