+ 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.

21st Mar 2018, 6:18 AM
Oma Falk
Oma Falk - avatar
11 Answers
+ 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..
21st Mar 2018, 9:47 AM
sayan chandra
sayan chandra - avatar
21st Mar 2018, 1:36 PM
Oma Falk
Oma Falk - avatar
+ 5
1 + 4 = 5 2+8 = 10 4 + 16 = 20 now the same with that pairs for dividible 10...right @sayan?
21st Mar 2018, 3:08 PM
Oma Falk
Oma Falk - avatar
+ 4
just think about seperating last two bits: lasttwobits = num - num>>2 num = num>>2...
21st Mar 2018, 12:59 PM
Oma Falk
Oma Falk - avatar
+ 3
@sayan still hard challenge! 8 is nice (num >> 3)<<3 = num
21st Mar 2018, 12:39 PM
Oma Falk
Oma Falk - avatar
+ 3
@ sayan. yes! more than that: My collegeboy with that clear and smart brain is on the road again!
21st Mar 2018, 12:44 PM
Oma Falk
Oma Falk - avatar
+ 2
@Sayan done!
21st Mar 2018, 3:06 PM
Oma Falk
Oma Falk - avatar
+ 1
what i said...was acceptable or not oma@...??? okayy???
21st Mar 2018, 12:40 PM
sayan chandra
sayan chandra - avatar
+ 1
😁😁😁😁
21st Mar 2018, 1:05 PM
sayan chandra
sayan chandra - avatar
+ 1
great work
21st Mar 2018, 3:17 PM
sayan chandra
sayan chandra - avatar