In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use JavaScript bit XOR". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use JavaScript bit XOR.
Algorithm:
In-place operations, the most frequently used is the XOR operation ^, the rules are as follows:
1.A ^ a = 0, a ^ 0 = a, 2.a ^ b ^ a = a ^ a ^ b = 0 ^ b = b Note: the following two topics are simple XOR operations, one is the most basic XOR operation, and the other is a transformation problem that can be completed with a little transformation.
Topic 1: basic use of XOR
Code implementation:
Func singleNumber (nums [] int) int {if len (nums) = 0 {return 0} res: = 0 for _, v: = range nums {res ^ = v} return res} / / algorithm: / / using bit operations, XOR, a ^ a = 0, a ^ 0 = a ^ b / because the title is two numbers, and one number, it belongs to the perfect use category of ^, / / by the formula: a _ b ^ a = a ^ ab = 0b = b You can directly differentiate or manipulate the code. / / the result is the number with the number 1.
Topic 2: the deformation of XOR
Code implementation:
Func singleNumber (nums [] int) [] int {if len (nums) = = 0 {return nil} / / step1: cancel out the number tmp:= 0 for _, v:=range nums {tmp ^ = v} / / step2: find the first bit iGRO for {n: = 1
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.