bit-shift

Bit Twiddling Hacks: interleave bits the obvious way

i am interested on this problem Interleave bits the obvious way (from http://graphics.stanford.edu/~seander/bithacks.html) unsigned short x; // Interleave bits of x and y, so that all of the unsigned short y; // bits of x are in the even positions and y in the odd; unsigned int z = 0; // z gets the resulting Morton Number. ...

Large binary shifts in 8086 assembly?

I have a binary chunk of data 512 bytes long, I was wondering what the most efficient way would be if I wanted to shift it once to the right. My best guess right now (very new to assembly) would be that I would have to first check a chunk (probably int) to see what it would shift out, shift, then carry in whatever the previous int would...

Converting some assembly to VB.NET - SHR operator working differently?

Well, a simple question here I am studying some assembly, and converting some assembly routines back to VB.NET Now, There is a specific line of code I am having trouble with, in assembly, assume the following: EBX = F0D04080 Then the following line gets executed SHR EBX, 4 Which gives me the following: EBX = 0F0D0408 Now, in V...

What is the << operator doing in C++?

In the example below, what exactally is the << operator doing? I'm guessing it is not a bitwise operator. std::cout << "Mouse down @ " << event.getPos() << std::endl; I understand what the code will do here: Use standard out, send this text, send an end of line. Just I've never come accross the use of this << apart from on raw binary....

shifting left and then immediately shifting right in asm?

disclaimer : I'm an asm newbie. I probably need to review my 2s complement or something to fully comprehend :( I'm confused as to the purpose of the following: .... BL some_func MOV R3, R0,LSL#16 MOVS R3, R3,LSR#16 .... why the shift back? and the movs? ...

Specifics about shifting floating point data types in .Net?

If I remember right, a double or float is broken into 3 parts: a sign bit, the exponent, and the mantissa. When a double is shifted, do the bits shift the entire binary of the variable or does it just shift the mantissa? ...

I don't understand the following C code line

I found the following thread: http://stackoverflow.com/questions/777617/calculate-broadcast-address-from-ip-and-subnet-mask and there the link to http://lpccomp.bc.ca/netmask/netmask.c Could someone please explain the following line, I don't understand: for ( maskbits=32 ; (mask & (1L<<(32-maskbits))) == 0 ; maskbits-- ) especially...

How do I shift out bits in C?

I am trying to write a function in C that will shift out the individual bits of a byte based on a clock signal. So far I have come up with this... void ShiftOutByte (char Data) { int Mask = 1; int Bit = 0; while(Bit < 8) { while(ClkPin == LOW); DataPin = Data && Mask; Mask = Mask * 2; Bit+...

Are there any good reasons to use bit shifting except for quick math?

I understand bitwise operations and how they might be useful for different purposes, e.g. permissions. However, I don't seem to understand what use the bit shift operators are. I understand how they work, but I can't think of any scenarios where I might want to use them unless I want to do some really quick multiplication or division. Ar...

Logical, arithmetical bitwise shifts

Seeking to clarify something. It is my understanding that with regard to arithmetical, logical bitwise shifts: << work the same for both >> shifts differ in which logical shift will always pad byte with 0, whereas arithmetical shift will pad it with the sign bit. How can i differentiate this using C? From what i understand, actual...

Why does left shift operation invoke Undefined Behaviour when the left side operand has negative value?

In C bitwise left shift operation invokes Undefined Behaviour when the left side operand has negative value. Relevant quote from ISO C99 (6.5.7/4) The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type, the value of the result is E1× 2E2, reduced modulo on...

Logical shift right operation on signed integer

Logical shift right by 3 operation on signed integer -28. What's the correct answer? +203 +83 +3 -3 2's complement of -28 is 11100100. Now if I apply logical right shift operation I am not getting any one of above answers. ...

What does >> do in java?

Okay, I tried looking up what >>, or shift means, but it's way over my head as this site explains it: http://www.janeg.ca/scjp/oper/shift.html So can someone explain it like they're talking to a kid? ...

Behaviour of unsigned right shift applied to byte variable.

Consider the following snip of java code byte b=(byte) 0xf1; byte c=(byte)(b>>4); byte d=(byte) (b>>>4); output: c=0xff expected output: c=0x0f how? as b in binary 1111 0001 after unsigned right shift 0000 1111 hence 0x0f but why is it 0xff how? ...

arithmetic shift

what is the difference between logical right shift and arithmetic right shift? ...

Why use the Bitwise-Shift operator for values in a C enum definition?

Apple sometimes uses the Bitwise-Shift operator in their enum definitions. For example, in the CGDirectDisplay.h file which is part of Core Graphics: enum { kCGDisplayBeginConfigurationFlag = (1 << 0), kCGDisplayMovedFlag = (1 << 1), kCGDisplaySetMainFlag = (1 << 2), kCGDisplaySetModeFlag = (1 << 3), ...

What is 0xFF and why is it shifted 24 times?

#define SwapByte4(ldata) \ (((ldata & 0x000000FF) << 24) | \ ((ldata & 0x0000FF00) << 8) | \ ((ldata & 0x00FF0000) >> 8) | \ ((ldata & 0xFF000000) >> 24)) What does that 0x000000FF represent? I know that decimal 15 is represented in hex as F, but why is it << 24? ...