www.delorie.com/archives/browse.cgi | search |
From: | DavMac AT iname DOT com (Davin McCall) |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: Re[2]: Bit counting? |
Date: | Tue, 17 Aug 1999 06:33:31 GMT |
Organization: | Monash Uni |
Lines: | 33 |
Distribution: | world |
Message-ID: | <37b9010b.24972024@newsserver.cc.monash.edu.au> |
References: | <37b4e020 DOT 2582291 AT newsserver DOT cc DOT monash DOT edu DOT au> <792 DOT 990817 AT Phreaker DOT net> |
NNTP-Posting-Host: | damcc5.halls.monash.edu.au |
X-Trace: | towncrier.cc.monash.edu.au 934871554 4282 130.194.198.138 (17 Aug 1999 06:32:34 GMT) |
X-Complaints-To: | abuse AT monash DOT edu DOT au |
NNTP-Posting-Date: | 17 Aug 1999 06:32:34 GMT |
X-Newsreader: | Forte Free Agent 1.1/32.230 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
You are using "value" each time. You should only use it the first time, and use "tempvalue" after that. To use your example (value = 7d = 111b, 3 bits are set): >2 bit sequemce: >value = 7 >mask1 = 0000000000000111 & 0101010101010101 = 5 >mask2 = 0000000000000111 & 1010101010101010 = 2 >mask2 >>=1 = 1 >tempvalue = mask1 + mask2 = 5 + 1 = 6 >4 bit sequence: >value = 7 ----> rather, tempvalue = 6 >mask1 = 0000000000000111 & 0011001100110011 = 3 >mask2 = 0000000000000111 & 1100110011001100 = 4 ---> mask1 = 00000000000110 & 0011001100110011 = 2 mask2 = 00000000000110 & 1100110011001100 = 4 >mask2 >>= 2 = 1 >tempvalue = mask1 + mask2 = 3 + 1 = 4 .. = 2 + 1 = 3. Continuing the process will not change the value; "3" is the final answer. Hope this made things clear, Davin. __________________________________________________________ *** davmac - sharkin'!! davmac AT iname DOT com *** my programming page: http://yoyo.cc.monash.edu.au/~davmac/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |