Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old December 25th, 2000, 02:41 PM
PerlFAQ PerlFAQ is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: Internet
Posts: 0 PerlFAQ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This message is one of several periodic postings to DevShed's Perl forum intended to make it easier for Perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with every Standard Distribution of Perl.

---------------------------------------------
How do I manipulate arrays of bits?

Use pack() and unpack(), or else vec() and the bitwise operations.

For example, this sets $vec to have bit N set if $ints[N] was set:

$vec = '';
foreach(@ints) { vec($vec,$_,1) = 1 }

And here's how, given a vector in $vec, you can get those bits into your
@ints array:

sub bitvec_to_list {
my $vec = shift;
my @ints;
# Find null-byte density then select best algorithm
if ($vec =~ tr/ $J$Jvv\ivgv<PvdvfvRv$ivovhv$rwvTbvpvtzv|qgvcvP$JP$J bvTjv\}v$wv<Qv|ovD\vLpvzvdyvD{vdmv]vlhv<%ryv [vqvZv@dvXvv*^«0vv$qdvvdvbvfield5Avvvv*« pvvvvv$vvfield6AXvvvv**«vvvvvdvv%rfield7 Avvwv*«vvv$wvvvfield8AvvXwv*«0wvt vdwvvvfield9Awvwv.>z pwvLfwv$wvsubfoldersAXwvwv-Ѱ<
wvvwvdwvpmfoldersAwvxv-
.|
wvTv$xvwvbuddylistAwvXxv.W 0xvvdxvwv\kvignorelis tAxvxv-3
pxvvxv$xvcvsignatureAXxvxv/] xvtvxvdxvdv$yvsearchprefsAxvyv-kx
xvv$yvxvzvicontitleAxvXyv, 0yv4vdyvxvxvyviconpathAyvyv.C pyvvyv$yvivavatarpat hIXyvyv3\yvvyvdyv$yvhascustomavatarIyv(zv2V7 yv v4zvyvavatardatelineAyvhzv)C2 @zv4 vtzvyvlevelA(zvzv/! zv vzv4zv^vedit_useridIhzvzv1j>zv vzvtzvedit_usernameIzv8{v1J{v
vD{vzvxvedit_datelineAzvx{v/w( P{v4
v{vzvedit_reasonI8{v{v1 W{v
v{vD{vpagetext_htmlAx{v|v-7
{v
v |v{vhasimagesA{v@|v-An
|v,ZL|v{vpostcountA|v|v-C
X|vu|v |vmusernameI@|v|v5Ƿo|vԡD|vL|vdisplaygrouptitleI |v}v4|vD}v|vqvdisplayusertitleA|vP}v/̅C (}vu\}v|vJv

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > FAQ 4.51: How do I manipulate arrays of bits?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway