244 views
0 votes
0 votes

Data structure for loop.  What is oxf ? can somebody explain

1 Answer

Best answer
1 votes
1 votes

Let's take n = 17

$17_{10} = (10001)_{2}$

$count = 0$

 $(0xf)_{16} = (15)_{10} =(1111)_{2} $

$for(n; n > 0; n>>4)$

$count = count + table[ 17 & 15 ]  = count + table[1] = 0 + 1 = 1$

$n >> 4$ means right shift by 4 bits

$17 >> 4$ = 1

$count = count + table[1 & 15] =  1 + table[1] = 1 + 1 = 2$

$1 >> 4$ = 0 , loop will be terminated;

$count = 2$

Here we can see that there are 2 1's in the binary representation of $17$ 

selected by

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
2
DAWID15 asked Dec 22, 2022
525 views
Options:10, 12,14, 16, 18, 2020, 18, 16, 14, 12, 1012, 10, 16, 14, 20, 18NONE
0 votes
0 votes
0 answers
3
Vipin Rai asked Jan 5, 2019
186 views
0 votes
0 votes
0 answers
4
eyeamgj asked Oct 7, 2018
921 views
IN THE VIA HEAP LIST WHY IT IS O(LOGN) FOR SEARCHING??