Thread hex to decimal conversion (12 answers)
Opened by thegreatonech at 2010-06-10 15:05

Gast thegreatonech
 2010-06-10 15:55
#138189 #138189
maybe this can help:

what i've got:

a hash called %temp looking like this: (key and value) max.key =511
0 58
1 2
2 51
3 2
4 49
5 2
6 42
7 2
8 3a
9 2
10 33
11 2
12 2b
13 2
14 24
15 2
16 1c
17 2
18 15
19 2
20 d
21 2
22 6
23 2
24 fe
25 1
26 f7
.

my code is following:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
for ($x=0; $x<=511; $x=$x+2){

$z=$x+1;
if (hex($temp{$x}) > hex($temp{$z})){


$string1 = $temp{$z};
$length = length($string1);

if ($length eq 1){
$string1 = "0".$string1;
}

$string2 = $temp{$x};
$length1 =length($string2);

if ($length1 eq 1){
$string2 = "0".$string2;
}


$hexzahl = $string1.$string2;
$deczahl = hex($hexzahl);


$calibtemp{$y}= $deczahl;
$calibtemp1{$y}= $hexzahl;
}
else{

$string1 = $temp{$z};
$length = length($string1);

if ($length eq 1){
$string1 = "0".$string1;
}

$string2 = $temp{$x};
$length1 =length($string2);

if ($length1 eq 1){
$string2 = "0".$string2;
}

$hexzahl = $string2.$string1;
$deczahl = hex($hexzahl);
$calibtemp{$y}= $deczahl;
$calibtemp1{$y}= $hexzahl;
}

open (filename, ">>tempi.dat") or die "Fehler","\n";

print filename "$y"," ","$calibtemp{$y}","\n";
print filename "$y"," ","$calibtemp1{$y}","\n";

close (filename);
$y++;

}


but the problem is that here i putted always the string with the lower value in front of the string with the higher value but thats not always right. I think it has to be a misunderstanding of the description I mentioned before.

hope that can help
Last edited: 2010-06-10 15:56:50 +0200 (CEST)

View full thread hex to decimal conversion