in reply to Help comparing data in byte by shifting (>>) bits
Is it looking any better? Thanks, RVsub isbitset { my $bytetocheck = $_[0]; my $bittocheck = $_[1]; if (($bytetocheck >> $bittocheck) & 1) { return 1; } else { return 0; } } # End of isbitset function. ################################################## # I am testing all 8 bits to see which one is set. ################################################## printf ("\tByte %08b bit 0 => %d\n\n", ord $uh[0], &isbitset((ord $uh[0]), 0)); printf ("\tByte %08b bit 1 => %d\n\n", ord $uh[0], &isbitset((ord $uh[0]), 1)); printf ("\tByte %08b bit 2 => %d\n\n", ord $uh[0], &isbitset((ord $uh[0]), 2)); printf ("\tByte %08b bit 3 => %d\n\n", ord $uh[0], &isbitset((ord $uh[0]), 3)); printf ("\tByte %08b bit 4 => %d\n\n", ord $uh[0], &isbitset((ord $uh[0]), 4)); printf ("\tByte %08b bit 5 => %d\n\n", ord $uh[0], &isbitset((ord $uh[0]), 5)); printf ("\tByte %08b bit 6 => %d\n\n", ord $uh[0], &isbitset((ord $uh[0]), 6)); printf ("\tByte %08b bit 7 => %d\n\n", ord $uh[0], &isbitset((ord $uh[0]), 7));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help comparing data in byte by shifting (>>) bits
by ikegami (Patriarch) on Jun 15, 2006 at 21:42 UTC | |
|
Re^2: Help comparing data in byte by shifting (>>) bits
by japhy (Canon) on Jun 15, 2006 at 19:59 UTC | |
by unixhome (Novice) on Jun 15, 2006 at 20:06 UTC | |
|
Re^2: Help comparing data in byte by shifting (>>) bits
by unixhome (Novice) on Jun 15, 2006 at 19:49 UTC |