How do you convert base m to base n
Mostra commenti meno recenti
Hello guys. I know this is stupid but can someone help me about this. Im asked to convert any number or letter from base m to base n. from bimary to deci, vice versa, binary to hexa and vice versa, and binary to octal and vice versa WITHOUT using inbuilt matlab conversiom commands. Im only limited to the REM and MOD command. Can someone help me? I really dont know what todo. Thank you
So after reading comments Im heartly to say sorry. It's my first time here and I only rushed the question.
So here I first converted my input to a string using string2num. Then I used the length function to determine length of input. Now i'm stuck at the conversion. Because it is required that the code is IN general, not in piece by piece. Like binary to 3 binary to 4 like that. I know that using modulo and then having a remainder 0 will OUTPUT 0 and remainder 1 will OUTPUT 1 If we were to convert base m to base 2. I really am stuck now for the general coding, cause iknow theres a division and multiplication process here. Sorry for taking up your precious time
1 Commento
John D'Errico
il 8 Dic 2015
So start writing. Think down what it means to write a number in base N. WHAT DO THOSE DIGITS MEAN? Once you know that, you should be able to convert a digit string to base 10. (As a double precision number)
Now, how can you convert a number from base 10 (again, as a double) into base M? What, for example, does mod(x,M) tell you about the number x?
Break the problem down into small, sub-problems. This is always necessary for something that is too hard for you to solve as a whole.
Make an effort. If you are willing to give up without trying, then there is no reason for us to do your homework for you. MATLAB gurus help those who help themselves.
Risposta accettata
Più risposte (1)
Tarinda Tiushan
il 23 Ago 2016
0 voti
Try dec2bin ('decimal number to covert to binary') Ex. Dec2bin ('362728') Vise versa bin2dec
1 Commento
Walter Roberson
il 23 Ago 2016
John D'Errico comments:
This fails to answer the question as posed. It shows only how to convert between base 10 and 2, and it uses the build-in tools, when they were excluded from use in the question.
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!