Return-Path: william@bourbon.usc.edu
Delivery-Date: Tue Nov 14 22:15:04 2006
X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on merlot.usc.edu
X-Spam-Level:
X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,
NO_REAL_NAME autolearn=ham version=3.1.3
Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75])
by merlot.usc.edu (8.13.5/8.13.5) with ESMTP id kAF6F4lN032213
for ; Tue, 14 Nov 2006 22:15:04 -0800
Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1])
by bourbon.usc.edu (8.13.5/8.13.5) with ESMTP id kAF6AdFk025264
for ; Tue, 14 Nov 2006 22:10:39 -0800
Message-Id: <200611150610.kAF6AdFk025264@bourbon.usc.edu>
To: cs551@merlot.usc.edu
Subject: Re: cs551: bitvector
Date: Tue, 14 Nov 2006 22:10:39 -0800
From: william@bourbon.usc.edu
Someone wrote:
> I have question in the setting of bits in th bit vector.
> we are stating that each of the 256 asci char is goin to rep 4 bits
> in the example we have the sha1 for categories as 757
> which means the 1st bit of 350th asci char shud be set on. (due to the
> fact that rite most bit is 0 )
I'm not sure how you get 350. This is illustrated on slide
10 of lecture 21. If each ASCII character represents 4 bits
(known as a "nibble"), then turning bit n on means the
following. The number of the "0" ASCII characters to the
right of this nibble is (int)(n/4). To determine which bit
is on in this nibble, you should calculate "n mode 4". If:
n mod 4 == 0, ASCII nibble value is "1"
n mod 4 == 1, ASCII nibble value is "2"
n mod 4 == 2, ASCII nibble value is "4"
n mod 4 == 3, ASCII nibble value is "8"
757/4 = 189 and 757 mod 4 = 1. Therefore, there are 189 ASCII
"0" to the right of this nibble and the nibble value is "2".
This should check out with slide 10 of lecture 21 (each full
line has 48 ASCII characters).
But I wouldn't really do the above! I would not do calculation
in "nibbles". I would use an array of 128 bytes as the bit
vector and set bits in the 128-byte bit vector. When I need
to output it in ASCII, I'll call a function to do it.
> doesnt that mean the binary rep at that time wud be 0001 which is hex
> 0x1 and decimal 1 rather than 2
> similarly
> if the 2nd bit is to be set then binary rep at that time wud be 0010
> which is hex 0x2 and decimal 2
> and
> if the 3rd bit is to be set then binary rep at that time wud be 0100
> which is hex 0x4 and decimal 4
> and
> if the 4th bit is to be set then binary rep at that time wud be 1000
> which is hex 0x8 and decimal 8
This part is correct (which is what I meant by "n mod 4" above).
--
Bill Cheng // bill.cheng@usc.edu