bitwise-operators

Looking for real world examples of bitwise operations in PHP

Hey guys! I've been looking at bitwise operations as a way of speeding things up in critical areas. But most of what I find are just low level explanations. Would anyone be so kind as to briefly explain what practical situations i may find myself needing bitwise operations? Or perhaps a link to a good tutorial? Thanks! ...

XAML 'NOT' operator?

<Button IsEnabled="{Binding (Not IsDisabled)}" /> Is there a way to do it with pure xaml, or I will have to do it via code? PS. I asked the question knowing that I can create a boolean converter like this: <ValueConversion(GetType(Boolean), GetType(Boolean))> Public Class BooleanFlagSwitchConverter : Implements IValueConverter ...

What does the "|" in "int style = SWT.APPLICATION_MODAL | SWT.OK;" do (and how to Google it)?

I can't search for | in Google. If you had found it in a software source code that you are trying to interpret, you didn't know what it does and you couldn't ask other people for help, how would you find out what it does? ...

MSSQL2008: Bit arrays and bit-wise operations + database Brainstorm

Hi all. I have a coding problem where I have to store a 'note' and the dates the note applies to. Think of: Note 1 Hi, today Mr Client rang arranging these appointments. 30/8/2009, 31/8/2009, 5/9/2009 Note 2 Business as usual. 30/8/2009 Note 3 Restaurant is shut. 6/9/2009 I need to store the following data in a database, while maint...

Why does a "&&=" Operator not exist?

(a && b) has the same value as (a & b), but with && the expression b is not executed if a is false. In Java there is also an operator &=. a &= b is the same as a = a & b. Question: Why isn't there an operator &&=, at least in Java. Is there some reason why I would not make sense to have it, or is it simply that no one cares or needs it...

Performance of bitwise operators in javascript

One of the main ideas behind using bitwise operators in languages like C++/java/C# is that they're extremely fast. But I've heard that in javascript they're very slow (admittedly a few milliseconds probably doesn't matter much today). Why is this so? (this question discusses when bitwise operators are used, so I'm changing the focus of ...

One position right barrel shift using ALU Operators?

I was wondering if there was an efficient way to perform a shift right on an 8 bit binary value using only ALU Operators (NOT, OR, AND, XOR, ADD, SUB) Example: input: 00110101 output: 10011010 I have been able to implement a shift left by just adding the 8 bit binary value with itself since a shift left is equivalent to multiplying...

C# Bitwise OR needs casting with byte *sometimes*

I found an odd situation in the C# compiler. Why the cast below is required? using System; class Program { private const byte BIT_ZERO_SET = 1; private const byte BIT_ONE_SET = 2; private const byte BIT_TWO_SET = 4; static void Main(string[] args) { byte b = BIT_ZERO_SET | BIT_ONE_SET; Console.Write...

What bit shifting techniques should I be using?

I'm curious to know what usage patterns people have established for themselves to utilize bit shifting in a modern day context such as client/server, web, desktop development. What's a usage of bit shifting in software development other than device drivers, asm? What bitwise operations / shifting techniques should I be using? What are s...

Why is this statement true in PHP?

I don't understand why this statement in PHP echos 'whaaa?' -- (0x0F | 0xF0) should be 0xFF no? if((0x0FFFFFFF | 0xF0FFFFFF) != 0xFFFFFFFF) echo 'whaaa?'; ...

Which method of incrementing is superior in C++?

I saw someone use this method to increment a variable: r = (r + 1) & 0xf; Is that method better/faster than just using: r++; Why would someone use a bitwise and, with 0xf, if it just duplicates? ...

Finding if a number is the power of 2 in Scheme

I'm fairly new to Scheme and am attempting to learn it on my own from scratch. I'm stuck on the syntax of this problem. I know that if I want to find out if a number is a power of 2, in C for instance, I would simply do: return (x & (x - 1)) == 0; which would return true or false. How would I be able to convert this into a couple simp...

How do I pre preform bit operations in glsl.

How do I pre preform bit operations in glsl? Using the regular C style bitwise operators |, &, ^, or ! do not work. ...

how to perform bitwise operation on floating point numbers

i tried this: float a = 1.4123; a = a & (1 << 3); i get a compiler error saying that operand to & cannot be of type float. when i do: float a = 1.4123; a = (int)a & (1 << 3); i get the program running. only thing is that the bitwise operation is done on the integer representation of the number obtained after rounding off. float a...

Effect of a Bitwise Operator on a Boolean in Java

The bitwise operators are supposed to travel the variables and operate on the bit by bit. In the case of integers, longs, chars this makes sense. These variables can contain the full range of values enforced by their size. In the case of booleans, however, a boolean can contain only two values. 1 = true or 0 = false. But the size ...

Long type, left shift and right shift operations.

Hi Continuing my previous question http://stackoverflow.com/questions/1782927/why-i-cannot-derive-from-long I found an interesting problem. Step one: 4294967296 & 0xFFFFFFFF00000000 Result: 4294967296. Step two. 4294967296 & 0x00000000FFFFFFFF Result: 0 Aha, So here I assume that 4294967296 == 0xFFFFFFFF Let's check (long...

Bit Shifts on a C Pointer?

I'm in the middle of this C project that I wish to make very memory efficient. In several cases, I am using the void *s of a dynamic array structure I wrote in order to hold bits. I wish to use all 64 (in this case) bits. I soon realized that you cannot actually do any bit manipulation on a pointer. So my solution was the following: ...

Equivalent of Java triple shift operators (>>> and <<<) in C#?

What is the equivalent (in C#) of Java's >>> operator? Just to clarify, I'm not referring to the >> and << operators. ...

Bitwise Or: C# versus C++

Hi ::- ). Assume you have two integers, a = 8, b = 2. In C++ a | b is true. I used that behavior to work with collections of flags. For example the flags would be 1, 2, 4, 8 and so on, and any collection of them would be unique. I can't find how to do that in C#, as the | and & operators don't behave like they would in C++. I read docume...

Java + bitwise operation

Hi All, I have a long variable in java and am converting it to a binary string, like long var = 24; Long.toBinaryString(val); Now this prints only 7 bits, but I need to display all the 64 bits, i.e. all the leading zeros also, how can I achieve this? The reason is I need to iterate through each bit and perform an operation according ...