Problem writing byte values to a file

From: Gregory K. Deal (gregory_deal_at_hotmail.com)
Date: 11/27/03


Date: Wed, 26 Nov 2003 21:39:00 -0500

I'm trying to write out bytes to a file with values anywhere from 0 to
255. I assign a value to a variable and write it out with a "%c" format.
Something like :

$r=1; $g=128; $b=1;
printf("%c%c%c",$r,$g,$b);

The problem is when the byte values exceed 127. When less than 128, I get
expected values (writing either a 1 or a 127) :

0000000 P 6 \n 3 3 \n 2 5 5 \n 001 177 001 001 001
0000020 177 001 001 177 \n 001 177 001 001 001 177 001 001 177 \n 001
0000040 177 001 001 001 177 001 001 177 \n

When I try to write a 128 (or larger), it seems to want to write the value
out in 2 bytes instead of 1 :

0000000 P 6 \n 3 3 \n 2 5 5 \n 001 302 200 001 001
0000020 001 302 200 001 001 302 200 \n 001 302 200 001 001 001 302 200
0000040 001 001 302 200 \n 001 302 200 001 001 001 302 200 001 001 302
0000060 200 \n

Here, a "302 200" seems to show up where the "177" used to be, when I
really only expected a plain "200". So, any idea what's going on here? Am
I jumping into or enabling Unicode mode? I tried "use bytes" to turn off
this behavior, but no luck. Trying the following didn't help either :

 $rc=chr($r); $gc=chr($g); $bc=chr($b);
 print "${rc}${gc}${bc}";

How can I predictably write out bytes to a file? Thanks for any help or
guidance.



Relevant Pages

  • Re: Bubba
    ... It's skill I lack not luck. ... fix. ... Virtually everything thing I've learned is from guidance, ... example, and experimenting here. ...
    (alt.gathering.rainbow)
  • Can two similar data bases be made into one?
    ... Would like to merge data bases. ... No luck with linking, or ... Simple" for guidance. ...
    (microsoft.public.access.gettingstarted)
  • Re: (Septembre, 18th) Picture of the week.
    ... Yes, I have spent many hours puzzling over that one, where is he jumping ... How did HCB know he would do that? ... recently done so because the water is dead still.) ... man's heel touched the water must have taken monumental luck, ...
    (uk.rec.photo.misc)
  • Re: Games, CD & Windows Media Player
    ... of Windows XP Power Toys: ... Good luck ... >Your guidance and information would be highly aprreciated. ...
    (microsoft.public.windowsxp.help_and_support)
  • RE: convert files to wav
    ... I, too, have been trying to convert an audio file in Madia to the wav format, with absolutely no luck! ... Any help or guidance will be greatly appreciated! ...
    (microsoft.public.windowsxp.music)