+ 9
[Challenge] check if a number is divisible by 10 or 3 or 8 with bitwise operators. 8 is middle, others are hardcore IMHO
Example: It is easy for checking an odd number with bitwise and -operator(&) number & 1 =(!) 1. it is a more mathematical problem, so it will not be in lesson assignment.
11 Antworten
+ 8
divisibility with 3
convert the no. to bin
seperate the no. by two bits..
add'em up
if ans is two bit and 11..then divisible
else two bit and 01 or 10 then not divisible..
if greater than 2 bit repeat pairing and adding
eg-->
69
0100101..bin
01 00 01 01..2 bit pairs
11..2 bit and 11
accept
49
110001..bin
11 00 01..2 bit pair
100..add
01 00..2 bit pair
1..add
....reject..
+ 5
@sayan look!
https://code.sololearn.com/cjYX757NpOFC/?ref=app
+ 5
1 + 4 = 5
2+8 = 10
4 + 16 = 20
now the same with that pairs
for dividible 10...right @sayan?
+ 4
just think about seperating last two bits:
lasttwobits = num - num>>2
num = num>>2...
+ 3
@sayan still hard challenge!
8 is nice
(num >> 3)<<3 = num
+ 3
@ sayan.
yes! more than that: My collegeboy with that clear and smart brain is on the road again!
+ 2
@Sayan done!
+ 1
what i said...was acceptable or not oma@...???
okayy???
+ 1
😁😁😁😁
+ 1
great work