Logical shift negative numbers

So, I think i have found a bug in Labview.  I am using Labview 8.5
I have a very very simple Vi Where i want to Right shift a negative number.  For example:
-16 >> 2 = -4
What i get is 16380.  If I mismatch the data types.  Meaning I right shift from a 16 integar and place the result into a 8 bit integar I get -4.  
It would appear that the function is padding with leading zeros and not ones when handling negative numbers.   
Is this an issue that has been fixed already?  Or am i using the function incorrectly?
Attachments:
Logical Shift bug.vi ‏7 KB

Gruntboy,
     What I think you're looking for is an arithmetic shift function, while the function in Labview is a logical shift.  The difference is in the leading bit of the result when they shift a number to the right.  A logical shift right pads the numbers with '0's and an arithmetic shift right pads the numbers with their copies of their most significant bit.  This is very important when dealing with signed numbers, because the most significant bit (in standard two's complement notation) denotes whether or not a number is negative. 
     The number four (4) represented in six bits would be: 000100, and in two's complement negative four (-4) would be 111100.
A logical shift right, which pads the numbers with a '0' on the left would be:
000100 --> 000010  (4 --> 2)
111100 --> 011110  (-4 --> 30)
An arithmetic shift right, which pads the numbers with whatever their most significant bit is would be: 
000100 --> 000010  (4 --> 2)
111100 --> 111110  (-4 --> -2) 
I don't see  an arithmetic shift function in Labview, but you could build one by converting the number to an array of booleans and shifting to your heart's content.
When operating on signed numbers Arithmetic shift operations tend to be more useful, but I'm sure there would be quite a bit of confusion if the unsigned number 60 ("111110") gets right shifted and becomes 127! ("111111").
Finally, there is "one" (heh I'm so punny) special case for arithmetic shifting.  Consider how right shifting (logical and arithmetic) 8 results in 4, then 2, then 1, then 0.  What about arithmetic right shifting of -8?  The results would be -4, then -2, then -1...... then -1, then -1, then -1, etc. 
Worthwhile resources:
Two's compliment notation for negative binary numbers: http://en.wikipedia.org/wiki/Two's_complement
Logical shift explanation (w/ pictures!): http://en.wikipedia.org/wiki/Logical_shift
Arithmetic shift explanation (w/ pictures!): http://en.wikipedia.org/wiki/Arithmetic_shift
I hope this helps!
Hugs,
memoryleak 
P.S. I noticed that you mentioned you were modeling number operations of an ASIC.  This book (ISBN: 978-0534378042) was used in the Intro to Digital Logic class I took way too long ago, and I remember it hitting very hard on binary, signs and bit operations.  Looks like a used copy can be had on Amazon for less than $40 
Message Edited by memoryleak on 10-09-2009 11:00 AM

Similar Messages

  • Negative numbers in export to excel

    Hi,
    We have two servers, one (X) without SP1 and the other (Y) with SP1.
    When I make export to excel in X, the negative numbers sometimes saved as @ or the actual negative number (e.g. -42), in both cases it is saved as text.
    The positive numbers are saved as numbers.
    We saw that SAP fixed it in SP1, we tried it on Y, we got that the negative numbers always show (e.g. -42), but all the numbers, positive and negative are saved as text.
    We need to see all the actual numbers(without @), and to be saved as numbers (so we can make calculations on them).
    Does anyone have any idea?
    Thanks.

    I am on SP1 and noticed that sometimes they are saved as numbers and some are texts:
    So I am not sure of any logic or what is going on.
    Maybe as a work around you could format everything to numbers so you can do the calculation?

  • How to shift Negative sign from Right to left

    Hi friends,
    please tell me How to shift Negative sign from Right to left for quan data type i am getting on right side but i want to display it on left exactly preceding my output number display.

    hi yogesh
    check this function module..
    <u><i><b>CLOI_PUT_SIGN_IN_FRONT</b></i></u>
    this will move the negative sign from the left hand side of a number, to the right hand side of the number. Note that The result will be left justified (like all character fields), not right justifed as numbers normally are.
    chck this example..
    data: a1 type i value 56 ,
    a2 type i value 60,
    res type i.
    res = a1 - a2.
    data: res1(10).
    res1 = res.
    CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
    CHANGING
    VALUE = res1
    write res1.
    I<u><i><b>MPORTANT</b></i></u>
    You can use this FM CLOI_PUT_SIGN_IN_FRONT.
    But you need to declare the amount field as char.
    Or you can code like this
    data int type i.
    data char(10).
    int = -4.
    int = int * -1.
    write int to char.
    concatenate '-' char into char.
    reward if useful..
    Message was edited by:
            navjot sharma

  • Why is my Macbook pro clock running negative numbers?

    My Macbook Pro clock is running negative numbers.

    When something of interest is on the screen, shift-command-3 will take a complete screenshot, or shift-command-4 puts up cross-hairs to let you choose just part of the screen. Either way, the screenshot is put on your desktop as "Screenshotn.png" (where the n is 1,2,3 or whatever, depending on what is there already). When composing a post in Apple discussions, click the little camera icon in the editing toolbar and you can select the image to be included with your post.

  • Is anyone having trouble using parenthesis to show negative numbers in excel after upgrading to Yosemite?

    Since upgrading to Yosemite, I can no longer reflect negative numbers with parenthesis using excel.  All of my existing spreadsheets also no longer show parenthesis, creating formatting problems.  Is anyone else experiencing this and is there a solution?

    I suggest you post your question to Microsofts own forums for their Mac software as it's their product you're having issues with
    http://answers.microsoft.com/en-us/mac

  • How do I disallow negative numbers in a selected group of cells (i.e. only allow values greater than or equal to zero)?

    I have a table of calculated values in Numbers, and I want to disallow negative numbers in the entire table. Any numbers that would be negative I would like changed to/displayed as zeroes, that way future calculations that may be based on this cell use the value of 0 for the calculation rather than the negative value. I have seen ways of doing this to single cells at a time, but I am interested in applying it to a large selection of cells.
    There is the Conditional Format option when you bring up the inspector, but I cannot get a custom rule to work for me. I select "Greater than or equal to" and I enter 0 in the box, but nothing changes. Can anyone help with this?
    Thanks

    A step toward simplifying the application of MAX to the issue, Jerry.
    This part, though:
    Now apply your long, animal-modeling, expressions to this new, interposing, table rather than the original.
    may still leave several references to be change from the original data table to the new one.
    One way to get around that is to use the Duplicate ("DATA-1) as the new table for raw data, and the Original (DATA) as the interposing table, using the formula =MAX(DATA-1::A2) as above, starting in DATA::A2.
    This way, the long expressions could continue to reference the original table (with its content now modified).
    ALTERNATE process:
    Find/Replace could also be used to speed the process of reassigning the modeling expressions to the duplicate table, as suggested by Jerry. But some cautions apply here.
    Find/Replace can be limited to Formulas only, but not to Some formulas only.
    Find/Replace can be limited to the Current Sheet only, but this can't be combined with Formulas only.
    More on this later, when I've had a chance to check some possibilities.
    Regards,
    Barry

  • How exactly does the logical shift function work?

    I think I am missing something very basic here - I am trying to left shift an 8 bit unsigned integer by one place (x<<1)in each iteration of a while loop. So if I start with a number, say 18, the first iteration I get 36, then 72, 144 and after this 32, 64 and so on. I'm not able to do this apparently simple operation in LabVIEW. I tried the logical shift function and a formula node, but both dont give me what I need. The formula node appears to be close in that it gives me 18,36,72,144 but after that I get 255 rather than 32. I dont understand what the logical shift function is doing here. I have attached a vi here that shows what I am trying to do. Any help explaining the mistake I am making will be greatly apprec
    iated.
    Thanks.
    Attachments:
    Logical_Shift.vi ‏17 KB

    You have the inputs confused. If you want to left-shift by 1 at each iteration, the "1" goes on the upper "y" terminal and the number from the shift register (the "shiftee") goes at the bottom. (see attached modification).
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Logical_Shift_2.vi ‏27 KB

  • Negative Numbers importing wrong

    I have a Stored Procedure on my SQL Server 6.5 DB that returns a list of decimal values (sql datatype is decimal(5,2)), of which most are Negative numbers. When the procedure is run in a SQL tool (MS Query or ISQL) the values are returned correctly. When the stored procedure is called in Java, all values (negative or positive) are showing up as zero.
    I have tried all of the following ...
    double d = rs.getDouble(1);
    Float f = rs.getFloat(1);
    Double d2 = new Double(rs.getDouble(1));
    BigDecimal b = rs.getBigDecimal(1);
    String s = rs.getString(1);The value returned by the procedure should look something like -14.75 but when using System.out.println(f.toString()); it is shown as ".00". I have even tried exporting the data out of Java into MS Excel to see if it is just something funny with the System.out.println() statement but it shows all zeros in Excel also.
    Is there anything special or a specific data type that must be used for negative numbers to read correctly in Java? I've searched the forum, tutorials and API (1.3) and haven't found anything like this.
    Any help would be greatly appreciated!!!

    So why do you say the error has something to do with negative numbers when (in your own words): "all values (negative or positive) are showing up as zero"? I don't know what your problem is, but negative numbers probably ain't it.

  • HFM 9.3 - FR Studio - can't format negative numbers with minus sign prefix?

    How can negative numbers on an account balance report be made to appear with a leading minus sign??
    This is a necessary requirement for generating an export file for loading to our new Tax software, but does not appear to be a format option.

    Have you tried going into Format Cells - Number - Negative Number Symbols - and typing a minus sign in the prefix box?

  • Where in the function palette can i find the "logical shift" function (shift x by y bits)?

    i am not able to find the "logical shift" function anywhere on the functions palette (after searching EVERY where). however, i discovered the function elsewhere in another VI (by pure luck!). i could keep bringing up these VI and copying and pasting, but that's a pain...i'd like to just have it on my functions palette to begin with.
    i am running labview 6.1 thanks for your help.

    hi,
    LabVIEW's functions pallete has come with a very useful tool --> "Search" tool
    Make use of the "Search" tool should you encounter difficulty in locating the desired function. For instants, search for keyword "Logical" or "Shift" and you will be able to locate the function
    happy coding
    Ian F
    Since LabVIEW 5.1... 7.1.1... 2009, 2010
    依恩与LabVIEW
    LVVILIB.blogspot.com

  • Negative numbers in Parentheses() in Interactive Reports in Apex 4.1

    Hi,
    I want to display the negative numbers in parentheses() in all the interactive reports in my application eg: (367,432,203.07).
    I tried using the PR format "999G999G999G999G990D00PR" in my number/date format option in 'Column Definition'. But it gives the negative number '-367432203.06895' like this '<367,432,203.07>', which is not my exact requirement.
    Is there any other number format/option to get negative numbers in parentheses in my reports.
    Can anyone please help me on this?

    divya wrote:
    I want to display the negative numbers in parentheses() in all the interactive reports in my application eg: (367,432,203.07).
    I tried using the PR format "999G999G999G999G990D00PR" in my number/date format option in 'Column Definition'. But it gives the negative number '-367432203.06895' like this '<367,432,203.07>', which is not my exact requirement.
    Is there any other number format/option to get negative numbers in parentheses in my reports.No. In 4.1 the only way to do this that preserves IR sort/aggregation/calculation functionality is to manipulate the values using a Dynamic Action/JavaScript after the page is rendered. This is not really satisfactory.
    In 4.2 I think it might be possible using a lot of extra columns, HTML Expressions, and CSS.

  • Flex 2 Stacked Bars with Negative Numbers?

    Hi guys, the strangest thing: I have a client requesting
    sacked bars for bar charts/column charts however, I can't seem to
    get the negative numbers to go below a positive x-axis.
    Do these bug logs suggest I need Flex 3?
    https://bugs.adobe.com/jira/browse/FLEXDMV-921
    https://bugs.adobe.com/jira/browse/FLEXDMV-1181
    and if that's the case, how will upgrading effect my current
    project?
    Thank you.

    Great, as in another thread defined and discused, i am
    a scripter, not a programmer, but i like oaying with math.
    Daves method is easy, but what about Random( -300,1200).
    that must be a huge array to initialize.
    my function has a restriction:
    it works only, if there is a zero in the range or you'll
    never get the highest number of the range. Also it can only have a
    linear range.
    Dave can input a list like this gRandomChoises = [
    1,3,5,7,11,13,17] , what can be very usefull in some cases.
    Cheers,
    Wolfgang

  • Pda reproducible bug with logical shift operation when y 3 for arrays

    Folks,
    I have discovered a problem and wonder if this is a wider bug or if I am doing something wrong:
    Labview PDA 8.0.1  -  running on a Dell Axim:
    I create a 2x1000 array of U32 and feed it as x into the logical shift operator.  If  y is between -3 and 3, the logical shift works properly.  If y >= 4 or <= -4, then the array is returned with all zeros.
    I have reproduced this for I32 data and smaller arrays.  Logical shift works properly for scalars.
    Has anyone else seen this?  Is this a bug?
    Thanks for any help.

    It might very well be a bug. If it works differently on the PC and on the PDA then it is almost certainly one.
    I suggest you post a simple example showing this so that people with current versions of the PDA module (i.e. not me) can test this. Maybe it was even fixed for 8.2?
    Try to take over the world!

  • Uni project methods & negative numbers arrghhh

    Hi there i have written a program for uni it creates a random number & gives the user 3 guesses at getting the number before giving them a message saying they have lost and revealing the actual number. So far so good . I managed to get this working but the next part of the project requires me to use a method which gives the user a message giving them a hint. The hint tells them whether they are hot, warm, cold etc.
    I have tried to implement this in my program using this code but its not working im getting 3 messages like
    ERROR: 'class' or 'interface expected
    Also i think my use of negative numbers is wrong i can remember someone telling me you have to change the negative number into a positive before u can manipulate it or something like that.
    Anyway any help would be greatly appreciated.
    import javax.swing.*;
    import java.util.*;
    public class Coursework1{
         public static void main(String args[]){
              int randomnumber,usersguessint,checkguess,guessvalid,attempts;
              String usersguess,output,close;
              boolean match;
              //create random number generator
              Random numGenerator = new Random();
              //generate a random number between 1 & 10 inclusive
              randomnumber = Math.abs(numGenerator.nextInt(9))+1;
                   //ask user for his first guess
                   usersguess=JOptionPane.showInputDialog("Please enter your guess between 1 & 10");
                   //convert users guess to integer
                   usersguessint = Integer.parseInt(usersguess);
                        //initialize variable attempts
                        for ( attempts = 0; attempts < 2; attempts++ ) {
                        //validate input
                        while (usersguessint<1||usersguessint>10){
                        usersguess=JOptionPane.showInputDialog("You entered an incorrect number \nPlease enter a numberbetween 1 & 10");
                         //convert users guess to integer
                        usersguessint = Integer.parseInt(usersguess);
                        } //end while loop
                             //call boolean method
                             match = checkGuess(usersguessint, randomnumber);
                             if (match==true){
                             //display text area in JoptionPane
                             output="You won";
                             JOptionPane.showMessageDialog(null,output,"You Won",JOptionPane.INFORMATION_MESSAGE);
                             break;}
                             else{
                             //call boolean method
                             close = howClose( usersguessint, randomnumber);
                             output="You were"+close;
                             JOptionPane.showMessageDialog(null,output,"hint",JOptionPane.INFORMATION_MESSAGE);
                             output="Try again";     
                             usersguess=JOptionPane.showInputDialog("Try again");
                             usersguessint = Integer.parseInt(usersguess);
                                  }     //end if
                   } //end for
              }//end main
                             //user defined method (chechguess)
                             public static boolean checkGuess(int usersguessint,int randomnumber){
                             boolean match = false;
                             if (usersguessint == randomnumber){
                             match = true;
                             return match;
                             }//end method
                             //user defined method (howClose)
                             public static String howClose(int usersguessint,int randomnumber){
                             String close
                             int difference;
                             difference = randomnumber-userguessint
                             if((difference<2)&&(difference>-2)){
                                  if((difference<3)&&(difference>-3)){
                                       if((difference<4)&&(difference>-4)){
                                            close="cold";
                                       }//end if
                                  else{
                                       close="warm";
                                  }//end if     
                             else{
                                  close="hot";
                             return close;     
                             }//end method
         }//endclass

    Yep, faulty as designed.
    try this:public static String howClose(int usersguessint, int randomnumber) {
              int difference;
              difference = randomnumber - usersguessint; // <---
              if ((difference < 2) && (difference > -2)) {
                   return "hot";
              if ((difference < 3) && (difference > -3)) {
                   return "warm";
              return "cold";
         }// end method

  • Negative Numbers considered as VARCHAR while uploading CSV file under Data Load in APEX

    I am trying to upload a CSV file which contains negative numbers. These negative numbers are being considered as VARCHAR2 while uploading. And if I change the Column Type to Numbers the upload fails.
    Any solutions the problem will highly be appreciated.

    select * from nls_database_parameters
    where parameter = 'NLS_NUMERIC_CHARACTERS'
    shows you which characters your database believes represent the decimal place and the thousands separator. So, if your database expects 1,234.123 and you present a 'number' as 1 234,123 it will complain.
    Also, in your case... your comma-separated-values contain commas? Or are the individual fields enclosed with quotes?

Maybe you are looking for

  • Displaying Query filters on a report to print

    I would like to display the query filters that I have used in my query filters display on the report, is there any way to do this? Are you able to create a variable and populate it with the query filters?

  • Error 403 in icloud

    who to be fixed error 403 in icloud

  • APPCS5.5 Clip Marker Sync Question

    Very simple scenario: Within Adobe Premiere Pro CS5.5, I inport (1) single video, minus audio. I then import (1) audio track, completely not associated with the audioless video clip. (For sake of this scenario, (1)video of gun shot - no sound, (1)aud

  • New 3tb Seagate drive external USB enclosure MAC OS X 10.6.8...

    I just purchased a new 3tb Seagate drive to replace a 2tb drive in an external USB enclosure, I can access, partition and format it using Parallels but can't even see it in Disk Utilities on Mac OS X 10.6.8...????!!!!! Any Help? I beleive it has a Jm

  • Tuner Not Working

    Actually, I can make it "function" .... but I can't find a way to incorporate it into my performances so it behaves properly. I just want to map a footswitch so I can tune my guitars, and want tuning available in each patch. Nothing unreasonable. If