Convert decimal to binary/octal/hexadecima value and vice versa
10 views (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 3 Dec 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 .)
Answers (2)
TyTy
on 3 Dec 2018
4 Comments
Walter Roberson
on 3 Dec 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
on 3 Dec 2018
2 Comments
Walter Roberson
on 3 Dec 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 .
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!