shift

Is 'shift' evil for processing Perl subroutine parameters?

眉间皱痕 提交于 2019-11-30 04:30:50
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 ? The use of shift to unpack arguments is not evil. It's a common convention and may be the fastest way to process arguments (depending on how many there are and how they're passed). Here's one example of a somewhat common scenario where that's the case: a simple accessor. use Benchmark qw(cmpthese); sub Foo::x

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

爷,独闯天下 提交于 2019-11-30 01:41:52
问题 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 回答1: char can be signed or unsigned - it's implementation-defined. You see these results because char is signed by default on your compiler. For the signed char 0xFF corresponds to −1 (that's how two's complement work). When you try to

resize UIView when showing the keyboard for iphone, how to? [duplicate]

给你一囗甜甜゛ 提交于 2019-11-29 23:36:47
问题 This question already has an answer here: How to resize UITextView on iOS when a keyboard appears? 10 answers I will show you an example with the well known whatsapp When you touch inside the text the keyboard pops up , so I have to move or shift all that bar up and resize the view to half, so I can still see the text that I'm typing and the send button Phase 1: http://www.appbank.net/wp-content/uploads/2010/10/WhatsAppMessenger-18.jpg Phase 2: http://www.onetooneglobal.com/wp-content/uploads

Is the shiftkey held down in JavaScript

﹥>﹥吖頭↗ 提交于 2019-11-29 11:03:54
I have written a JS function that only allow numbers to be entered. A copy of that function is below: function NumbersOnly(e) { var evt = e || window.event; if (evt) { var keyCode = evt.charCode || evt.keyCode; //Allow tab, backspace and numbers to be pressed, otherwise return false for everything. //(keyCode>=96 && keyCode<=105) are the numpad numbers if ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105) || keyCode === 9 || keyCode === 8) { } else { evt.returnValue = false; } } } This function works fine with all the numbers but my problem happens when the shift key is

Google Chrome console.log out of sequence? [duplicate]

老子叫甜甜 提交于 2019-11-29 07:28:51
This question already has an answer here: Is Chrome's JavaScript console lazy about evaluating arrays? 7 answers Can someone explain the following two outputs? Code 1: console.log(itemsAry); //loadNextItem(); function loadNextItem(){ var item = itemsAry.shift(); console.log(item); } Result: ["cat-53", "cat-57", "cat-51", "cat-10", "cat-55", "cat-56", "cat-5", "cat-50", "cat-3", "cat-54", "cat-52", "cat-9", "cat-8", "cat-4", "cat-58", "cat-6", "cat-7"] (as expected). Code 2: console.log(itemsAry); loadNextItem(); function loadNextItem(){ var item = itemsAry.shift(); console.log(item); } Result:

Bitshifting in Java

大憨熊 提交于 2019-11-29 03:41:39
问题 I'm trying to understand how bit shift works. Can someone please explain the meaning of this line: while ((n&1)==0) n >>= 1; where n is an integer and give me an example of a n when the shift is executed. 回答1: Breaking it down: n & 1 will do a binary comparison between n, and 1 which is 00000000000000000000000000000001 in binary. As such, it will return 00000000000000000000000000000001 when n ends in a 1 (positive odd or negative even number) and 00000000000000000000000000000000 otherwise. (n

Is 'shift' evil for processing Perl subroutine parameters?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 01:46:08
问题 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 ? 回答1: The use of shift to unpack arguments is not evil. It's a common convention and may be the fastest way to process arguments (depending on how many there are and how they're passed). Here's one example of a

Detect CTRL and SHIFT key without keydown event?

本小妞迷上赌 提交于 2019-11-28 12:13:12
I've been wondering if I can detect CTRL and SHIFT key being pressed WITHOUT using keydown event. The reason is that I am creating some sort of Grid Viewer in JavaScript, and I implemented selecting different items by holding CTRL or SHIFT key as it functions in most common viewers, editors and so on. The problem is that when the focus is not anywhere on the page. For example I'm adding page to the bookmarks. Then I hold CTRL or SHIFT and click on the item, but it acts normally as keydown hasn't been triggered. Any way of omitting this? Perhaps not, but it can be confusing for customers who

Verilog Barrel Shifter

只愿长相守 提交于 2019-11-28 11:34:04
I want to create a 64-bit barrel shifter in verilog (rotate right for now). I want to know if there is a way to do it without writing a 65 part case statement? Is there a way to write some simple code such as: Y = {S[i - 1:0], S[63:i]}; I tried the code above in Xilinx and get an error: i is not a constant. Main Question: Is there a way to do this without a huge case statment? I've simplified some of the rules for clarity, but here are the details. In the statement Y = {S[i - 1:0], S[63:i]}; you have a concatenation of two signals, each with a constant part select. A constant part select is of

Bison Shift/reduce error for C-like language

≡放荡痞女 提交于 2019-11-28 10:02:08
问题 I'm having an issue with my bison grammar, it is giving me shift/reduce errors, and I have already defined precedence for the operators. I know that it is cause by the 'expr binop expr' bit of the expr rule. Here is my bison file, and the output I get. Any help would be very much appreciated. %token ID KEYWORD INTCON FLOATCON TYPE STRING %token IF WHILE FOR VOID RETURN %token AND_OP OR_OP EQ_OP NEQ_OP LEQ_OP GEQ_OP %left OR_OP %left AND_OP %nonassoc '<' LEQ_OP '>' GEQ_OP EQ_OP NEQ_OP %left '+