Thread Hex to signed Integer (1/256) (9 answers)
Opened by JuMi2006 at 2012-09-17 11:15

GUIfreund
 2012-09-17 22:28
#161883 #161883
User since
2011-08-08
559 Artikel
BenutzerIn
[default_avatar]
Das Encoding geht z. B. so (leider kein Einzeiler):
Code (perl): (dl )
1
2
3
4
5
6
7
8
sub encode_b2d {
    my $y = shift;
    $y *= 256;
    $y = $y & 0xffff if ($y < 0);
    my $hb = int $y/256;
    my $lb = $y % 256;
    return (sprintf("%0.2X", $hb), sprintf("%0.2X", $lb));
}

Aufruf:
Code (perl): (dl )
1
2
    ($hb, $lb) = encode_b2d($y);
    say "$y -> ($hb, $lb)";
Gruß
GUIfreund

View full thread Hex to signed Integer (1/256)