Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!stanford.edu!msi.umn.edu!umeecs!zip!bagchi From: bagchi@eecs.umich.edu (Ranjan Bagchi) Newsgroups: comp.lang.perl Subject: vec() weirdness Message-ID: Date: 19 Jun 91 18:11:49 GMT Sender: usenet@zip.eecs.umich.edu (Mr. News) Organization: Recreational Creationists, Inc. Lines: 77 I'd been needing to see the bits of 32-bit ints on a Sparc. I hadn't been having much luck, so I tried the following script: #!/usr/bin/perl -- for (1,2,4,8,16,32) { $word = "\0" x 32; print "BITS = ",$_,":\n"; vec($word,0,$_) = 1; print unpack("b32",$word),"\n"; print "1234567890" x 4; print "\n"; } __END__ gives: BITS = 1: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 2: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 4: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 8: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 16: 00000000100000000000000000000000 1234567890123456789012345678901234567890 BITS = 32: 00000000000000000000000010000000 1234567890123456789012345678901234567890 but shouldn't it be: BITS = 1: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 2: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 4: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 8: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 16: 10000000000000000000000000000000 1234567890123456789012345678901234567890 BITS = 32: 10000000000000000000000000000000 1234567890123456789012345678901234567890 perl -version gves me: This is perl, version 4.0 $RCSfile: perl.c,v $$Revision: 4.0.1.1 $$Date: 91/04/11 17:49:05 $ Patch level: 3 Copyright (c) 1989, 1990, 1991, Larry Wall Perl may be copied only under the terms of the GNU General Public License, a copy of which can be found with the Perl 4.0 distribution kit. Can anyone explain this? -rj -- -------------------------------------------------------------------------------- Ranjan Bagchi - asleep...... | v,i,j,k,l,s,a[99]; bagchi@eecs.umich.edu | main() { ------------------------------- for(scanf("%d",&s);*a-s;v=a[j*=v]-a[i],k=i=s*k&&++a[--i]) ; } /* Osovlanski and Nissenbaum */ --------------------------------------------------------------------------------