Perform bitwise NOT on given int. Arguments: i {[int]} -- [given int] Raises: ValueError -- [input is negative] Returns: Result of bitwise NOT on i >>> not_32(34) 4294967261 >>> not_32(1234) 4294966061 >>> not_32(4294966061) 1234
(i: int)
| 188 | |
| 189 | |
| 190 | def not_32(i: int) -> int: |
| 191 | """ |
| 192 | Perform bitwise NOT on given int. |
| 193 | |
| 194 | Arguments: |
| 195 | i {[int]} -- [given int] |
| 196 | |
| 197 | Raises: |
| 198 | ValueError -- [input is negative] |
| 199 | |
| 200 | Returns: |
| 201 | Result of bitwise NOT on i |
| 202 | |
| 203 | >>> not_32(34) |
| 204 | 4294967261 |
| 205 | >>> not_32(1234) |
| 206 | 4294966061 |
| 207 | >>> not_32(4294966061) |
| 208 | 1234 |
| 209 | >>> not_32(0) |
| 210 | 4294967295 |
| 211 | >>> not_32(1) |
| 212 | 4294967294 |
| 213 | >>> not_32(-1) |
| 214 | Traceback (most recent call last): |
| 215 | ... |
| 216 | ValueError: Input must be non-negative |
| 217 | """ |
| 218 | if i < 0: |
| 219 | raise ValueError("Input must be non-negative") |
| 220 | |
| 221 | i_str = format(i, "032b") |
| 222 | new_str = "" |
| 223 | for c in i_str: |
| 224 | new_str += "1" if c == "0" else "0" |
| 225 | return int(new_str, 2) |
| 226 | |
| 227 | |
| 228 | def sum_32(a: int, b: int) -> int: |