Hướng dẫn convert to reverse binary python - chuyển đổi thành python nhị phân đảo ngược
Bạn cũng có thể sử dụng bảng tra cứu (có thể được tạo khi sử dụng các phương thức ở trên): Cải thiện bài viết Lưu bài viết Cho một số nguyên dương và kích thước của bit, đảo ngược tất cả các bit của nó và trả về số với các bit được đảo ngược. Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 1 Chúng ta có thể giải quyết vấn đề này một cách nhanh chóng trong Python. Cách tiếp cận rất đơn giản,
Phương pháp int () hoạt động như thế nào?Phương thức int (chuỗi, cơ sở) lấy một chuỗi và cơ sở để xác định rằng chuỗi đang đề cập đến hệ thống số nào (nhị phân = 2, hexadecimal = 16, octal = 8, v.v.) và chuyển đổi chuỗi thành hệ thống số thập phân cho phép. Ví dụ ; int (‘1010, 2) = 10. method takes a string and base to identify that string is referring to what number system ( binary=2, hexadecimal=16, octal=8 etc. ) and converts string into decimal number system accordingly. For example ; int(‘1010’,2) = 10. Python3
Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 10 = Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 12 Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 13 Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 14 Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 15 Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 14 Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 15 Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 13 Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 14 def 0
Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 10 = ____1010____25
Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 15
Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 14
Một cách khác để hoàn nguyên các bit mà không chuyển đổi thành chuỗi:
Thực hiện theo các bước để thực hiện ý tưởng này:
Dưới đây là việc thực hiện phương pháp nhất định. Python3
Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 14 = 2Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 13 Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 14
Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 13 = 9
Input : n = 1, bitSize=32 Output : 2147483648 On a machine with size of bit as 32. Reverse of 0....001 is 100....0. Input : n = 2147483648, bitSize=32 Output : 15
|