472,980 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 software developers and data experts.

Converting Hex Fraction to Dec

How might I convert a string like 10.A (in hex) to it's decimal equivalent?
Basically I have an input string like ((1F.A + 3A.D) - 1F.E) and need to
calculate the result. Using Reflection and dynamic compilation, I was able
to create a VB.NET equivalent of the older Eval function, but it only works
with decimal numbers.

Any thoughts? I know the logic to convert, but I was hoping for some
built-in .NET methods that I could leverage

jeff
Oct 12 '06 #1
5 5527
The question has to asked:

Where does this 'input string' come from?

If it comes from some abstract exercise on your part then your time would be
better utilised musing in the question of 'Life, The Universe and
Everything'.

If it comes from some 'real world' data provider/producer, then you need to
asking the question of that data provider/producer because they, and only
they, can tell you what rules need to be applied and how they should be
applied. If they can't, or won't tell you, then you are, (excuse my french),
farting against thunder.

That said, I must add -

The decimal system has a widely acccepted set of rules that allow one to 'do
math' on decimal numbers, regardless of whether the operands are integral or
fractional. However, the decimal representation of a value must always be
considered in it's context. For example, the number 10.5 could represent 10
dollars and 50 cents or it could represent 10 and a half days or it could
represent 10 and a half widgets. There are accepted extensions to decimal
notation to indicate context like money being shown in conjunction with a
currency symbol and there are other extensions to indicate signage (+ and -)
while there are still other extensions to make the representation more
readable, like thousands seperators. This makes it easy to show a number
like $10,000.00 and everybody should interpret as ten thousand dollars
without any ambiguity.

Hexadecimal, on the other hand, is nothing more than a notational system and
it primary use is for representing binary values in a more human readable
form. It has no widely accepted extensions for indicating context, signage
or readability.

Take the hexadecimal value FF. What does it represent? It could represent
255 as a byte. It could represent -1 as a signed byte. It could represent 2
seperate 4-bit values of 15 each. The longer the string of hexadecimal
characters the more permuatations there are of possible meanings.

The next point is that hexadicamal notation has no concept of a 'hexadecimal
point' and therefore has no rules regarding placeholding to the right of
such a point (if it were to exist).

You cannot apply the rules that govern the use of a decimal point because
those rules relate only to the the decimal system and have no meaning in
any other 'base' system.

"Jeff Dillon" <je****@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
How might I convert a string like 10.A (in hex) to it's decimal
equivalent? Basically I have an input string like ((1F.A + 3A.D) - 1F.E)
and need to calculate the result. Using Reflection and dynamic
compilation, I was able to create a VB.NET equivalent of the older Eval
function, but it only works with decimal numbers.

Any thoughts? I know the logic to convert, but I was hoping for some
built-in .NET methods that I could leverage

jeff

Oct 12 '06 #2
I must admit, *fractional* hex is pretty weird; I've never seen it used
and can't imagine what it would be used for. But Stephany, I don't see
why you think this is so ambiguous.

It's pretty obvious to me that the data type is a hex Float. What
*unit* it represents - days, dollars, ducks - is irrelevant.

In decimal, the numbers proceeding leftwards from the decimal point
represent:
1's
10's
100's
1000's
etc.

And from the right mean:
1/10's
1/100's
1/1000's
etc.

Yes, that's all obvious - but stick with me. In hex, proceeding from
the left of the decimal point:
1's
16's
256's
4096's

So we logically extend this consistent pattern to determine what the
hex numbers to the right of the decimal represent:
1/16's
1/256's
1/4096's

There's nothing magic about the minus sign either. If present, it
would denote a negative number regardless of numerical base.

And we can do that for any number system and/or precision. 2.5
(decimal) could be exactly represented as:

10.1 (binary)
2.4 (octal)
2.8 (hexadecimal)
2.G (base-36)

Yes, I've actually used base-36; it uses the numbers and *all* the
letters. (I used it for shrinking a long decimal number, such as a
drive serial, into the smallest possible easily human-readable/typable
string for keycode-based software registration.) I have some functions
that will correctly convert decimal to/from *any* arbitrary numerical
base, from binary to base-36, and everything inbetween.

It doesn't do fractions, though! And I'm sorry, but I can't help with
the original query within the conditions specified - using a built-in
VB language trick to facilitate conversion.

Oct 13 '06 #3
Correction: 2.5 (decimal) = 2.I (base-36). What can I say, I'm not
good at doing base-36 conversions in my head. :)

Oct 13 '06 #4
I have no idea about your very odd response.

This is a take-home interview question, you idiot

You wasted your time (and mine) in your nonsense reply. Of course other base
systems can have decimal points

I didn't need a stupid lesson in hex numbers. Get a life
"Stephany Young" <noone@localhostwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
The question has to asked:

Where does this 'input string' come from?

If it comes from some abstract exercise on your part then your time would
be better utilised musing in the question of 'Life, The Universe and
Everything'.

If it comes from some 'real world' data provider/producer, then you need
to asking the question of that data provider/producer because they, and
only they, can tell you what rules need to be applied and how they should
be applied. If they can't, or won't tell you, then you are, (excuse my
french), farting against thunder.

That said, I must add -

The decimal system has a widely acccepted set of rules that allow one to
'do math' on decimal numbers, regardless of whether the operands are
integral or fractional. However, the decimal representation of a value
must always be considered in it's context. For example, the number 10.5
could represent 10 dollars and 50 cents or it could represent 10 and a
half days or it could represent 10 and a half widgets. There are accepted
extensions to decimal notation to indicate context like money being shown
in conjunction with a currency symbol and there are other extensions to
indicate signage (+ and -) while there are still other extensions to make
the representation more readable, like thousands seperators. This makes it
easy to show a number like $10,000.00 and everybody should interpret as
ten thousand dollars without any ambiguity.

Hexadecimal, on the other hand, is nothing more than a notational system
and it primary use is for representing binary values in a more human
readable form. It has no widely accepted extensions for indicating
context, signage or readability.

Take the hexadecimal value FF. What does it represent? It could represent
255 as a byte. It could represent -1 as a signed byte. It could represent
2 seperate 4-bit values of 15 each. The longer the string of hexadecimal
characters the more permuatations there are of possible meanings.

The next point is that hexadicamal notation has no concept of a
'hexadecimal point' and therefore has no rules regarding placeholding to
the right of such a point (if it were to exist).

You cannot apply the rules that govern the use of a decimal point because
those rules relate only to the the decimal system and have no meaning in
any other 'base' system.

"Jeff Dillon" <je****@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>How might I convert a string like 10.A (in hex) to it's decimal
equivalent? Basically I have an input string like ((1F.A + 3A.D) - 1F.E)
and need to calculate the result. Using Reflection and dynamic
compilation, I was able to create a VB.NET equivalent of the older Eval
function, but it only works with decimal numbers.

Any thoughts? I know the logic to convert, but I was hoping for some
built-in .NET methods that I could leverage

jeff


Oct 13 '06 #5
Your response is correct.

There is no easy answer here

Jeff
<te******@hotmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>I must admit, *fractional* hex is pretty weird; I've never seen it used
and can't imagine what it would be used for. But Stephany, I don't see
why you think this is so ambiguous.

It's pretty obvious to me that the data type is a hex Float. What
*unit* it represents - days, dollars, ducks - is irrelevant.

In decimal, the numbers proceeding leftwards from the decimal point
represent:
1's
10's
100's
1000's
etc.

And from the right mean:
1/10's
1/100's
1/1000's
etc.

Yes, that's all obvious - but stick with me. In hex, proceeding from
the left of the decimal point:
1's
16's
256's
4096's

So we logically extend this consistent pattern to determine what the
hex numbers to the right of the decimal represent:
1/16's
1/256's
1/4096's

There's nothing magic about the minus sign either. If present, it
would denote a negative number regardless of numerical base.

And we can do that for any number system and/or precision. 2.5
(decimal) could be exactly represented as:

10.1 (binary)
2.4 (octal)
2.8 (hexadecimal)
2.G (base-36)

Yes, I've actually used base-36; it uses the numbers and *all* the
letters. (I used it for shrinking a long decimal number, such as a
drive serial, into the smallest possible easily human-readable/typable
string for keycode-based software registration.) I have some functions
that will correctly convert decimal to/from *any* arbitrary numerical
base, from binary to base-36, and everything inbetween.

It doesn't do fractions, though! And I'm sorry, but I can't help with
the original query within the conditions specified - using a built-in
VB language trick to facilitate conversion.

Oct 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Krista Bailie | last post by:
I'm sure this is so easy that it will hurt for anyone to read it, but I really need some direction. I'm trying to create a color chart (RGB) that shows steps between two different colors as...
25
by: TK | last post by:
I'm used to programming in c or c++ in which my problem is simple. I want to be able to enter a value on a page (like 3.2), and then read it as a 32-bit float and break it into it's individual...
2
by: Benjamin Rutt | last post by:
Does anyone have C code laying around to do this? I have to read in some binary data files that contains some 4-byte IBM/370 floating point values. I would like a function to convert 4-byte...
5
by: Valerie Hough | last post by:
Is there a C# class that will help convert strings that include fractions ( "2 1/2" e.g.) to doubles ? Convert.ToDouble() throws an invalid input format exception. Obviously I can write code to...
4
by: M. Uppal | last post by:
How do i convert fraction to time in c#. I need to convert 0.25 to time. Excel does this by using Selection.NumberFormat = "h:mm:ss;@" of the Cell Format function. thanks, M. Uppal
0
by: amarok | last post by:
Hello all. I'm a Software Engineering student, and I'm attempting to write a program in Java that does as follows: UML for the class: Fraction() Fraction(numerator: int) ...
6
evilmonkey
by: evilmonkey | last post by:
I am very new to programming as well as Java and this is my first post so please forgive me if this is not quite posted correctly. My Problem is that I have only been using scanner to get user input...
1
by: d0ugg | last post by:
Hi, I'm did a fraction program for one of my programming classes and it did compile, however when I'm running the program it crashes for some reason that I do not know. // fraction.cpp ...
2
by: d0ugg | last post by:
Hi, I'm doing a FRACTION program for one of my Programming classes and I'm getting some errors that I can't figure it out. Here is the Assignment: 1. Convert the fraction structure into a...
4
by: d0ugg | last post by:
Hello everyone, I'm creating a program that it is suppose to add, subtract, multiply and also divide fractions and after that, the result has to be reduced to the lowest terms. However, I'm not...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.