in reply to Re: Re: Re: writing binary data in perl
in thread writing binary data in perl
But the question was ambiguous about the desired outcome. Writing out the 'int' value 1234 might mean (1) writing either a little- or big-endian 0x4d2, (2) writing a host- or network-order 0x4d2, or (3) writing out the unicode codepoint 1234. I picked interpretation #1. #2 should be done with pack(), but since the sample C code didn't include htonl() or a variant, it apparently wasn't desired. #3 should be done with either pack() or a plain chr(1234).
Except I'm still wrong, because I was really treating the 'int' as a 'short' and writing out only 16 bits. To match the C code, which wrote a 32-bit value, that should be chr(1234 & 0xff).chr(1234>>8).chr(0).chr(0) The distinction seemed unimportant for the simple goal of mentioning chr()!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: writing binary data in perl
by jmcnamara (Monsignor) on Apr 12, 2002 at 22:31 UTC |