Convert decimal to binary/octal/hexadecima value and vice versa
Afficher commentaires plus anciens
I'm trying to write a program that will convert a decimal number that a user inputs to a binary, octal and hexadecimal value. As well as convert a binary, octal and/or hexadecimal that user inputs to a decimal number. I can not use the functions matlab has to do this conversion. I have to create my own algorithms.I am not skilled in matlab so I do not know how to start or what to do.
Can someone help me
1 commentaire
Walter Roberson
le 3 Déc 2018
Okay so go ahead and create your own algorithms . Once you have decided on algorithms then start programming in MATLAB. If you run into problems you can post your commented code (that describes your algorithms ) and the error message and we will help you understand the error message. (We might or might not tell you whether your algorithms are correct , depends on our mood. So think about the algorithm .)
Réponses (2)
TyTy
le 3 Déc 2018
0 votes
4 commentaires
Walter Roberson
le 3 Déc 2018
Start by researching what binary and octal and hexadecimal number systems mean . Watch some YouTube on how to convert to binary .
Walter Roberson
le 3 Déc 2018
This is stuff I learned in grade 5 over 40 years ago. We are not going to hand you the solution . We are going to make you do your own research as to what the question means and how number systems work . Our role is to help you understand what MATLAB is telling you not to solve the assignment for you.
TyTy
le 3 Déc 2018
Walter Roberson
le 3 Déc 2018
How would you convert 13 decimal to binary by hand? How would you convert A5 hex to decimal ?
If you know how to do base conversion by hand then you have a place to start: write down the algorithm and then start converting to MATLAB statements .
TyTy
le 3 Déc 2018
2 commentaires
Walter Roberson
le 3 Déc 2018
MATLAB uses == for comparisons.
use input() with the 's' option to prompt and accept a value in the form of a character vector .
You might be tempted to accept values as numeric but that will fail for hex because of the A to F characters and will fail for more than 15 binary digits as you start to overflow representation . Process characters on input instead .
Really you only need two routines: one to convert aa character vector in an arbitrary base into numeric form and the other to convert numeric form to arbitrary base . There is no need for distinct routines to handle those bass. With just those two routines you could easily convert base 9 to base 19 for example .
TyTy
le 3 Déc 2018
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!