shift

Easy way to shift specific characters in a string in C++?

As an example, if I have the string: ".....ZZ..ZZ....." or ".Z.1.Z.23Z.4.Z55" is there an easy way that I can shift each Z in that string one space to the right? Thanks in advance, Tomek Some additional test strings: ".Z" "Z." "ZZ." ".ZZ" "Z" "ZZ" "ZZZ" I think a few of the higher voted answers to this question (including the cu...

What is the fastest way to get the 4 least significant bits in a byte (C++)?

I'm talking about this: If we have the letter 'A' which is 77 in decimal and 4D in Hex. I am looking for the fastest way to get D. I thought about two ways: Given x is a byte. x << 4; x >> 4 x %= 16 Any other ways? Which one is faster? Thanks. ...

iPhone keyboard shift key disabled

I have a UITextField where the keyboard that pops up has its shift key disabled. The keyboard type is set to UIKeyboardTypeNamePhonePad, which seems like it should allow capitals. If I change the keyboard type to "default" but leave other settings alone, the shift key is active. The other settings are: autocapitalization and autocorr...

Where can I find a bit shifting guide for C?

I have looked at http://stackoverflow.com/questions/141525/absolute-beginners-guide-to-bit-shifting but I still find the concept of bit shifting difficult to understand. Can someone point me in the direction of a more basic guide to bit shifting in C. I expect it will be something really long since it will need to cover the whole subjec...

PHP - pop first element of array instead of last (reveresed array_pop)?

Hi Is there a PHP function that would 'pop' first element of array? array_pop() pops last element, but I'd like to pop the first. ...

How to shift array elements

Hi, I have an array of n = 32 items with positive and negative values. First n/2 elements are positive and sorted by value and second n/2 elements are negative and sorted by value as well. I would like to sort the whole array by value, starting from the smallest negative value to biggest positive value which means if there are 32 elemen...

C# Winform Detect Shift Key on Application Startup

hi, is there a way to get a standard winform app to detect if the shift key is being held down on application startup - without using windows hooks? I ideally would like the workflow to change from normal if the shift key is held down when the exe is run. ...

In C Left shift (char) 0xFF by 8 and cast it to int

Hello People On left shift of (char) 0xff by 8 and casting it to int we get -256 or 0xffffff00. Can somebody explain why this should happen? #include <stdio.h> int main (void) { char c = 0xff; printf("%d %x\n", (int)(c<<8),(int)(c<<8)); return 0; } Output is -256 ffffff00 ...

How do you determine if a character requires the shift key to be down to be typed?

I am writing some code to type strings using the Robot class. Everything is mostly good (well, I have to use a big switch statement to get character keycodes), except some keys don't have keycodes, because they are actually a combination of SHIFT + some other key. For upper case letters, it is easy to check, using Character.isUpperCase...

Is 'shift' evil for processing Perl subroutine parameters?

I'm frequently using shift to unpack function parameters: sub my_sub { my $self = shift; my $params = shift; .... } However, many on my colleagues are preaching that shift is actually evil. Could you explain why I should prefer sub my_sub { my ($self, $params) = @_; .... } to shift? ...

Auto scrolling or shifting a bitmap in .NET

I have a .NET GDI+ bitmap object (or if it makes the problem easier a WPF bitmap object) and what I want to to is shift the whole lot by dx,dy (whole pixels) and I would ideally like to do it using .NET but API calls are ok. It has to be efficient bacause its going to be called 10,000 times say with moderately large bitmaps. I have imp...

Shifted text in swing app on OS X

Hi I have a little java+swing app. Until now it worked OK, on OS X and on windows. But recenly a user has noticed that on his OS X (version unknown yet, nor the java version) that all texts in the GUI are shifted up and cut (as you can see on the screenshot). And HTML link is shifted down and cut. All those elements are JLabels. Th...

Can I shift the objects in a NSMutableArray without creating a temporary array?

I thought I had it with, void shiftArray(NSMutableArray *mutableArray, NSUInteger shift) { for (NSUInteger i = 0; i < [mutableArray count]; i++) { NSUInteger newIndex = (i + shift) % [mutableArray count]; [mutableArray exchangeObjectAtIndex:i withObjectAtIndex:newIndex]; } } which turns 0,1,2,3,4 into 0,2,3,4,1 when I shift by o...

bash script to perform operation on each argument against the final argument

Suppose you want to make a bash script which supports no options but acts like cp, because the cp supplied by your system does not accept multiple sources. The usage for the system's (hypothetical and broken) cp is: cp source target # target may be a directory The usage for the script will be: cp.sh source... target # target m...

Matrix Circular Shift

Does anyone know an efficient way to right circular-shift a matrix? Btw, the matrix is binary but a method to solve a non-binary matrix is also fine. Right now, I'm thinking of implementing a circular array for the rows of my matrix and updating each row whenever a shift operation is required. Another method, I was considering was impl...

How to shift audio track without delay in AS2

Hi, I have written an application that plays 2 audio tracks in Flash. Now is my problem: how to make so, that after user have pressed a key, second track would be shifted(forwards/back)? This action and then playing should be without additional caching and delays. ...

uninterlace bits from 16 bit value

I have a 16 bit value with its bits "interlaced". I want to get an array of 8 items (values 0 to 3) that stores the bits in this order: item 0: bits 7 and 15 item 1: bits 6 and 14 item 2: bits 5 and 13 ... item 7: bits 0 and 8 This is a trivial solution: function uninterlace(n) { return [((n>>7)&1)|((n>>14)&2), // bits 7 and 15 ...

What are Scala continuations and why use them?

So I just finished "Programming in Scala" and I've been looking into the changes between Scala 2.7 and 2.8. The one that seems to be the most important is the continuations plugin but I don't understand what its useful for or how it works. I've seen that 'its good for async I/O' but I haven't been able to find out why. Some of the mor...

How do I shift an array of items up by 4 places in Javascript

Hi, How do I shift an array of items up by 4 places in Javascript? I have the following string array: var array1 = ["t0","t1","t2","t3","t4","t5"]; I need a function convert "array1" to result in: // Note how "t0" moves to the fourth position for example var array2 = ["t3","t4","t5","t0","t1","t2"]; Thanks in advance. ...

Autocorrelation and shift vectors

Basically I'll be using Autocorrelation method to try to find cloned regions within an image. This is what i did in MATLAB i = imread ('D:\image.jpg') I = rgb2gray(i); imshow(I); f = fspecial('LOG'); h = imfilter(I,f); x = xcorr2(double(h), double(h)); imagesc(x); figure(gcf) basically loading up an image, changing it to greyscale, ap...