473,383 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 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 5554
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.