Tag: Bit Manipulation
-
Algorithms 101: Using Bitwise AND to Check the Least Significant Bit
•
The bitwise AND operation is a fundamental tool in low-level programming, and it’s particularly useful when working with binary data. One common use case is to check whether a number is even or odd by examining its least significant bit (LSB). This technique is efficient and commonly used in performance-critical…
-
LeetCode: 371 Sum of Two Integers
•
Given two integers a and b, return the sum of the two integers without using the operators + and -. Example: Input: a = 1, b = 2 Output: 3 Example: Input: a = 2, b = 3 Output: 5 问题 给定两个整数 a 和 b,在不使用 + 和 – 运算符的情况下,返回两个整数的和。 解决方案…
-
LeetCode: 268 Missing Number
•
Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example: Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3].…
-
LeetCode: 191 Number of 1 Bits
•
Here’s a detailed explanation and solution for LeetCode 191: Number of 1 Bits, with explanations provided in both English and Chinese, line by line. Problem Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight). Example: Input:…