in reply to Re^2: Perl Hashes in C?
in thread Perl Hashes in C?
You are used to working with decimal numbers, but pack/unpack can be used to convert between binary, octal, decimal and hexadecimal. To use 48bit RGB, just think of the 6 octets as 3 16 bit numbers. Then this works:
A lot of monks here are better at the math than I, but I can hold my own most of the time!my $myNum = 65000 * (2**32); my ( $R,$G,$B ) = unpack("nnn", $myNum ); print "\$myNum: $myNum\n(\$R,\$G,\$B): $R\t$G\t$B\n";
For the future, ask specific questions that show your problem and when possible show the code that's demonstrating the problem. For your initial problem, you didn't have to worry about endianess, but you may have to consider it if your working with different architectures.
Good Luck...Ed
Regards...Ed
"Well done is better than well said." - Benjamin Franklin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl Hashes in C?
by Anonymous Monk on Aug 14, 2015 at 00:05 UTC |