Hi,
i'd like to know how to get hex code of an ASCII char.
Ex: 'a' => 61

Recommended Answers

All 2 Replies

sub ascii_to_hex ($)
    {
    	(my $str = shift) =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
    	return $str;
    }
    sub hex_to_ascii ($)
    {
    	(my $str = shift) =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg;
    	return $str;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.