Skip to main content
1-Visitor
November 18, 2012
Question

Converting Input Hex Data Strings to Number

  • November 18, 2012
  • 3 replies
  • 5582 views

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

3 replies

24-Ruby IV
November 18, 2012

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).

25-Diamond I
November 19, 2012

Even easier: append a "0" in front of every hexstring and then feed it in str2num.

WE

25-Diamond I
November 19, 2012

Something like the attached?

WE

19.11.png

24-Ruby IV
November 19, 2012
25-Diamond I
November 19, 2012

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