in reply to Re^3: How to convert binary to hexadecimal
in thread How to convert binary to hexadecimal

I believe the above posted code is incorrect. An example string that breaks this is:
0001111000001111000001111000001111000001111000001111000001111000001111 +000000000000000000000000000000000000000000000000000000000000000000000 +000000000000000000000000001111000001111000001111000001111000001111000 +00111100000111100000111100000111100000111100
One correct way of doing bin2hex is:
sub bin2hex { my $line = $_[0]; my $lenCount = 4; my $hexLine = ""; my $width = '4'; while ( length($line) % $width != 0) { $line = '0' . $line; } while ($lenCount <= length($line)) { my $x = substr ($line, -($lenCount), $width); $hexLine = sprintf("%X", oct("0b$x")).$hexLine; $lenCount += 4; } print "In bin2hex: $line\nAfter bin2hex: $hexLine\n\n"; return $hexLine; }

2020-03-04 Athanasius added code tags.