File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 50
50
* [ Index Of Rightmost Set Bit] ( bit_manipulation/index_of_rightmost_set_bit.py )
51
51
* [ Is Even] ( bit_manipulation/is_even.py )
52
52
* [ Is Power Of Two] ( bit_manipulation/is_power_of_two.py )
53
+ * [ Numbers Different Signs] ( bit_manipulation/numbers_different_signs.py )
53
54
* [ Reverse Bits] ( bit_manipulation/reverse_bits.py )
54
55
* [ Single Bit Manipulation Operations] ( bit_manipulation/single_bit_manipulation_operations.py )
55
56
Original file line number Diff line number Diff line change
1
+ """
2
+ Author : Alexander Pantyukhin
3
+ Date : November 30, 2022
4
+
5
+ Task:
6
+ Given two int numbers. Return True these numbers have opposite signs
7
+ or False otherwise.
8
+
9
+ Implementation notes: Use bit manipulation.
10
+ Use XOR for two numbers.
11
+ """
12
+
13
+
14
+ def different_signs (num1 : int , num2 : int ) -> bool :
15
+ """
16
+ Return True if numbers have opposite signs False otherwise.
17
+
18
+ >>> different_signs(1, -1)
19
+ True
20
+ >>> different_signs(1, 1)
21
+ False
22
+ >>> different_signs(1000000000000000000000000000, -1000000000000000000000000000)
23
+ True
24
+ >>> different_signs(-1000000000000000000000000000, 1000000000000000000000000000)
25
+ True
26
+ >>> different_signs(50, 278)
27
+ False
28
+ >>> different_signs(0, 2)
29
+ False
30
+ >>> different_signs(2, 0)
31
+ False
32
+ """
33
+ return num1 ^ num2 < 0
34
+
35
+
36
+ if __name__ == "__main__" :
37
+ import doctest
38
+
39
+ doctest .testmod ()
You can’t perform that action at this time.
0 commit comments