Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
I have a file of text that looks like this:
1 678H
2 3F4H
3 FC7H
.....
....
I am reading this in as data and want to do numerical calculations on the 2nd column, which represents hexidecimal numbers. MathCad things they are strings. Is there a way to force them to a data type of numeric, or, barring that, convert them with some function to type number?
Thanks
Fritz
May be this help you
http://twt.mpei.ac.ru/MCS/Worksheets/base2base.xmcd
Yu can convert the string "0FC7h" (hex) to the string "4039" (dec) and then use str2num function - 4039 (to dec number).
Even easier: append a "0" in front of every hexstring and then feed it in str2num.
WE
You missed something. Fritz' hex-data have already an "H" at the end!
This makes things a lot easier on the one side and makes your bas2base fail on the other.
Even if the "H" would be missing it would be easier to append it the same way the "0" is prepended rather than to strip it and use base2base. But probably thats a matter of taste.
Nevertheless your base2base() is a program nice to have and to learn from.
Attached is my version which I wrote some time ago as a quick hack. Therefore no errorchecking, etc.
WE
Werner Exinger wrote:
You missed something. Fritz' hex-data have already an "H" at the end!
WE
I think H is h (a postfix hex) in Mathcad
Valery Ochkov schrieb:
I think H is h (a postfix hex) in Mathcad
Yes, mathcad seems not to be case sensitive in this respect and because the "H" its already in the file you can use the built-in str2num straightforward (as long as the first character is a number, the reason for the leading "0") and do not have to resort to base2base conversion.
As someone in another thread asked, here is a new baseconversion with some basic error handling implemented.
I also attach a file in Prime3 format.
While copying the errormessages in the P3 file I noticed that copy and paste still does not work as it should - what a shame!
EDIT: Slightly modified the files