in reply to Color Converstion
Result:my $R = 0xF1; my $G = 0xE2; my $B = 0xD3; my $rgb_int = $R + ($G<<8) + ($B <<16); my $rgb_hex = uc unpack 'H6', pack 'V', $rgb_int; print $rgb_hex;
F1E2D3The way it works is by packing the long integer into a 4-byte binary string containing a Little Endian integer (red is first byte); and then unpack the first 3 bytes (= 6 nybbles, a nybble is half a byte) into a hex string, the higher nybble per byte coming first.
"h" swaps order of the nybbles per byte; "B" and "b" respectively do the same in binary, "B" running from the higher to the lower bit, and "b" from low to high.
|
|---|