i need m-file to convert decimal to hexadecimal without using the built in command deci2hex
Show older comments
i need m-file to convert decimal to hexadecimal without using the built in command deci2hex
Answers (2)
Walter Roberson
on 20 Dec 2013
hexstuff = sprintf('%x', decimalvalue)
2 Comments
malek ebrahem
on 20 Dec 2013
Walter Roberson
on 21 Dec 2013
decimalvalue = input('What value would you like to convert?');
hexstuff = sprintf('%x', decimalvalue);
disp(hexstuff)
Roger Stafford
on 20 Dec 2013
Edited: Roger Stafford
on 20 Dec 2013
0 votes
I won't give you an m-file, but here's an outline of how to proceed, Malek. If you are dealing with positive integers, do a mod(~,16) on your integer to get its least hex digit. It will range from 0 to 15. Next subtract this digit from your number and divide the difference by 16. Then repeat the above steps for the next higher hex digit. Continue this process, each time producing another higher hex digit, until the integer has been reduced to zero. The sequence of digits you have obtained this way constitute your number expressed in hexadecimal. This outline should help you to write your own conversion routine.
1 Comment
malek ebrahem
on 21 Dec 2013
Categories
Find more on Data Type Conversion 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!