Covert Value From Text Field "24.36" to a 32-bit Hex Value
Manraj P.
Mississauga, ON

Jan 13, 2010
1 Post

#### covert value from text field "24.36" to a 32-bit hex value

I am trying to take data from a text field (for example: "24.36") and convert that to a 32-bit hex value. Any help I can get on this would be very helpful. Thank you!

Steven H.
Riverside, CA

Jan 14, 2010
1 Post

#### Re: covert value from text field "24.36" to a 32-bit hex value

Converting a string to float or double uses the val command
fValue: float
sValue: string
sValue = "24.36"
fValue = val(sValue)
print fValue

What do you mean when you say you want to convert that  into a hex valu
For example, floats are converted into four byte (32-bits) values when writing to a modbus register?

John K.
Bacau,

Aug 15, 2010
55 Posts

#### Re: covert value from text field "24.36" to a 32-bit hex value

but how about converting a string to an integer? for example, I use nValue:short , sValue:string, sValue="24", nValue=val(sValue), print nValue, and it gives me an error because the "val" command returns a double, not a short... What can I do to convert that double to an integer? Can anyone please help me?

DrATEasy (Ron Y.)
Mission Viejo, CA

Aug 16, 2010
286 Posts

#### Re: covert value from text field "24.36" to a 32-bit hex value

The code:

s="24"
n=val(s)
print n

does not give any error (n is short), it prints 24. If you need to truncate the decimal portion of the returned double use:
s="24.25"
n=val(s)
print n

or use:

print (int(val(s))

ATEasy allow assigning double to any integer without any error or warning. Conversion of types in ATEasy is done automatically.
d=5.6
n=d
print d ! will print 5

If you need an ASCII representation of hexadecimal number use:
n=0x17
print str(n, 16)

This will print "11"