Topic
Hex to Dez conversion
- This topic has 6 replies and 2 voices and was last updated 18 years, 10 months ago ago by peter.zeyher@mechatronic.de.
-
AuthorPosts
-
17.07.2006 at 22:20 #33298peter.zeyher@mechatronic.deParticipant
I am trying to convert data in hex format to dez numbers using the following script. It won’t run because of a syntax error (behind the first else). The numbers are in the following format: 0xFFFF
Script is:
for i = 6 to 3 do
b = stringmid(test,i,1)
if (b = ‘F’) then (b=15) else
if (b = ‘E’) then b=14 else
if (b = ‘D’) then b = 13 else
if (b= ‘C’) then b =12 else
if (b = ‘B’) then b = 11 else
if (b= ‘A’) then b =10
end
end
end
end
end
end
D = D + (b * 16^(6-i))
end
return DThanks already
Peter
17.07.2006 at 22:20 #33304peter.zeyher@mechatronic.deParticipantI am trying to convert data in hex format to dez numbers using the following script. It won’t run because of a syntax error (behind the first else). The numbers are in the following format: 0xFFFF
Script is:
for i = 6 to 3 do
b = stringmid(test,i,1)
if (b = ‘F’) then (b=15) else
if (b = ‘E’) then b=14 else
if (b = ‘D’) then b = 13 else
if (b= ‘C’) then b =12 else
if (b = ‘B’) then b = 11 else
if (b= ‘A’) then b =10
end
end
end
end
end
end
D = D + (b * 16^(6-i))
end
return DThanks already
Peter
17.07.2006 at 23:15 #33299Bernhard KantzParticipantTry this:
[code]
Dim i, b, D
D = 0For i = 3 to 6 do
b = stringmid(test,i,1)
if (b == “F”) then (b=15)
elseif (b == “E”) then b=14
elseif (b == “D”) then b = 13
elseif (b== “C”) then b = 12
elseif (b == “B”) then b = 11
elseif (b == “A”) then b = 10
end
D = D + (b * 16^(6-i))
end
return D
[/code]18.07.2006 at 00:17 #33300peter.zeyher@mechatronic.deParticipantThanks!
The next problem is that I have a “Datenreihe mit … Zeichenketten” called ‘Test’ that I want to convert. The function Stringmid(Test,i,1) gives me the following error message: “Das erst Argument der Funktion Stringmid() hat falsche Datenstruktur. Das Argument muss ein Zeichenketten Einzelwert sein.”
How can I get the function to convert all the values ?
Thanks
Peter
18.07.2006 at 00:46 #33301Bernhard KantzParticipantUse the [b]index[/b] operator to get a scalar value from a data set.
Example:
[code]
Dim i, result
result = 0 # NumberOfRows(Test)
For Each Row i In Test Do
result[i] = HexToDez(Test[i])
End
result
[/code]
The HexToDez is a FPScript formula which converts Hex values into decimal values. This formula uses the [b]Arguments[/b] statement.See also
FlexPro Online Help (F1)18.07.2006 at 01:36 #33302peter.zeyher@mechatronic.deParticipantThanks a lot! This works for me now.
I have to use slightly different function (maybe because I am using FlexPro 6?):
Dim i,D, result
result = 0 # Numberofvalues(Weg)
For Each value i In Weg Do
D = HextoDez(Weg[i])
If D>60000 then D=D-65536
end
D=D/500
result[i] = D
End
resultand I had to do my own hextodez function which looks like this:
arguments h
Dim D,iD = 0
For i = 2 to 5 dob = stringmid(h,i,1)
if (b == “F”) then (b=15)
elseif (b == “E”) then b=14
elseif (b == “D”) then b = 13
elseif (b == “C”) then b = 12
elseif (b == “B”) then b = 11
elseif (b == “A”) then b = 10
end
D = D + (b * 16^(5-i))
endThe only problem is that this is quite slow (with 130000 numbers). Is there any possibility to speed the function up, or at least to have it calculate everything again as soon as I use the function in a diagram etc. ?
Thanks
Peter
18.07.2006 at 01:59 #33303Bernhard KantzParticipantHere is an alternative FPScript-Function:
[code]
dim chars, idx
dim a, res, i, n
chars = “0123456789ABCDEF”
a = “2FFF”
res = 0L
n = StringLength(a) – 1
For i = 0 to n Do
idx = StringFind(chars, StringMid(a, i, 1))
if idx < 0 then
return 0
End
res = res * 16 + idx
End
res
[/code]
You can convert your FPScript formula into a dataset. Alternatively you could use VBA with FlexPro Professional to convert your values. -
AuthorPosts
- You must be logged in to reply to this topic.