bitwise-operators

Notation for logic in Java

对着背影说爱祢 提交于 2019-12-23 08:23:30
问题 Absolutely basic Java question which I'm having a hard time finding on Google. What does the following mean: (7 & 8) == 0? Is that equivalent to writing: 7 == 0 || 8 == 0? I wrote a quick main which tests this, and it seems to be the case. I just wanted to make sure I'm not missing anything. 回答1: Nope. & is bitwise and. It sets a bit if the corresponding bits are set in both inputs. Since in binary, 7 is 111 and 8 is 1000 , they have no bits in common, so the result is 0 . There isn't really

How to check if permuted hexadecimal integers matches to another using Bitwise operations (performance optimization)

谁都会走 提交于 2019-12-23 02:36:25
问题 After discussing a little about optimization of a part from my code in a previous question and getting some low-level improvements, @SergGr suggested me creating a new question to try get a high-level improvement and reach my main goal. In my code I have to apply some moves in a "scrambled" square-1 puzzle object and, after, check if it was solved. As I found a better implementation of a square-1 puzzle object around internet I took it to be used in my Android application. Then, as you can

What is an intuitive way to interpret the bitwise operators and masking? Also, what is masking used for?

蹲街弑〆低调 提交于 2019-12-23 02:07:06
问题 I'm learning about bitwise operators and masking right now in my computer systems class. However I'm having some trouble internalizing them. I understand what the operators, &, |, ^, >> (both arithmetic and logical shift), and << DO, but I don't quite get what they're really used for aside from optimizing multiplication and division operations (for >> and <<), and to check if certain bits are on or off (the & operator). Also, I don't understand what masking is used for. I know that doing x &

Convert IPv6 to binary without INET6_ATON()

怎甘沉沦 提交于 2019-12-22 12:27:33
问题 Description: I am creating an IP class that first finds the visitor's IP address (using $_SERVER['REMOTE_ADDR'] or getenv('REMOTE_ADDR') ), makes sure it's a valid IP, set's the version (IPv4 or IPv6) to a data member, then it either returns the IP address, or returns the SQL parameter if it's for an SQL query (see createQueryParam() function below for available returns). Question: If the server is not running MySQL 5.6.3+, how can I convert a IPv6 binary stored in the database table (

Convert IPv6 to binary without INET6_ATON()

雨燕双飞 提交于 2019-12-22 12:27:08
问题 Description: I am creating an IP class that first finds the visitor's IP address (using $_SERVER['REMOTE_ADDR'] or getenv('REMOTE_ADDR') ), makes sure it's a valid IP, set's the version (IPv4 or IPv6) to a data member, then it either returns the IP address, or returns the SQL parameter if it's for an SQL query (see createQueryParam() function below for available returns). Question: If the server is not running MySQL 5.6.3+, how can I convert a IPv6 binary stored in the database table (

How to perform bitwise operations arithmetic in MS-ACCESS

只谈情不闲聊 提交于 2019-12-22 09:49:42
问题 Inside MSACCESS I want to use relatively simple bitwise operations in WHERE clause of queries such as this: SELECT * FROM Table1 WHERE Column1 (some operator) 8 = 0 This would: Return rows where Column1 does not have its 4th bit set e.g. 0, 1, 2, ..., 7 (all have their 4th bit clear) and 16 (it is 00010000b) Exclude rows where Column1 is 8, 9, 10, ..., 15 etc. PS: are bitwise operators different from boolean operations? 回答1: If you can run your query in in ANSI-92 Query Mode (e.g. by changing

Byte shift inverse operation

▼魔方 西西 提交于 2019-12-22 08:54:33
问题 I have this code byte[] b = new byte[]{-33,-4,20,30}; System.err.println(Arrays.toString(b)); int x = (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + b[3]; b = new byte[]{(byte)(x >> 24), (byte)(x >> 16), (byte)(x >> 8), (byte)(x)}; System.err.println(Arrays.toString(b)); Output: [-33, -4, 20, 30] [-34, -4, 20, 30] I cannot figure out why this operations are not invers. 回答1: Your problem is unwanted sign extension. Specifically, b[1] is -4 , or 0xfc which is sign-extended to 0xfffffffc then left

Byte shift inverse operation

喜欢而已 提交于 2019-12-22 08:54:22
问题 I have this code byte[] b = new byte[]{-33,-4,20,30}; System.err.println(Arrays.toString(b)); int x = (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + b[3]; b = new byte[]{(byte)(x >> 24), (byte)(x >> 16), (byte)(x >> 8), (byte)(x)}; System.err.println(Arrays.toString(b)); Output: [-33, -4, 20, 30] [-34, -4, 20, 30] I cannot figure out why this operations are not invers. 回答1: Your problem is unwanted sign extension. Specifically, b[1] is -4 , or 0xfc which is sign-extended to 0xfffffffc then left

Are bitwise operations still practical?

百般思念 提交于 2019-12-22 05:18:14
问题 Wikipedia, the one true source of knowledge, states: On most older microprocessors, bitwise operations are slightly faster than addition and subtraction operations and usually significantly faster than multiplication and division operations. On modern architectures, this is not the case: bitwise operations are generally the same speed as addition (though still faster than multiplication). Is there a practical reason to learn bitwise operation hacks or it is now just something you learn for

What is C# exclusive or `^` usage? [closed]

孤街浪徒 提交于 2019-12-22 04:55:08
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . Can anyone explain this operator with a good example? I know what this operator is. I mean a real-life example. 回答1: It is an