Odd or even number comparison?

Anyone know how to compare an incoming number and tell whether it is odd or even? How about if it is whole or fractional? Thanks
Kirk

fabb wrote:
Anyone know how to compare an incoming number and tell whether it is odd or even? How about if it is whole or fractional? Thanks
You need to be very careful applying odd/even to floating point numbers. It is only defined for intergers. Especially, if the value is a result of some computations, it could actually be 2.000000001 instead of 2.
Same with whole vs. fractional. You probably need additional code to ignore small differences from whole numbers. Where does the data come from?
ODD/EVEN: If you have an integer datatype, do a bitwise AND with "1" and check if the result is zero (even) or not (odd).
Message Edited by altenbach on 05-27-2008 09:17 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
OddEven.png ‏3 KB

Similar Messages

  • Create function for ODD or EVEN(NUMBER)  in pls sql

    create function for ODD or EVEN(NUMBER) also
    if number is odd multiply by 5
    if number is even multiply by 10;

    865253 wrote:
    create function for ODD or EVEN(NUMBER) also
    if number is odd multiply by 5
    if number is even multiply by 10;
    create function fn_get_no (n_in in number) return number is
    o_num number;
    begin
    if mod(n_in,2) = 0 then
    o_num := n_in*10;
    else
    o_num := n_in*5;
    end if;
    return o_num;
    end;
    select fn_get_no(5) odd, fn_get_no(4) even from dual;
    ODD EVEN
    25 40 Vivek L

  • Odd or even number

    ok , basically how can I write a line of code which will tell me if a number is odd or even?

    the test for equality with 0 should work for all numbers - the remainder of dividing a negative number by two should be 0 or -1 (I think - and the code bears this out anyway)
    Lee

  • Function detect odd and even number

    Do you know a function which can detect if a number is an odd number or other.

    if ( number%2 == 1)
    But a method for this? Really doubt that..
    Do you know a function which can detect if a number is
    an odd number or other.

  • How to find the largest odd number and smallest even number from an array

    Hello All
    I want to find out largest odd number and the smallest even number from an arry numbers? What is the best method to achieve this.
    Thanks
    Sravz

    You need to sit down and figure out an algo on how you would do it if you had to do the same thing from a blind container perspective:
    1 - collect all the items you want to look at
    2 - look at an item
    3 - is it odd?
    4 - if it is odd then check if it is larger than previously largest number
    5 - save it if it is larger
    6 - return back to 2 unless no more items
    7 - item is not odd so it must be even--is it smaller than previous
    8 - save it if it is smaller
    9 - return back to 2 unless no more items
    Now you just need to know how to check if something is even or odd: to do this you will need the modulous operator--integer division.
    Note: this all assumes that your needs are for integer type of numbers, otherwise there is not enough information to define an answer. For instance, if you are using floats at 0.5--it that even or odd? Do you consider an err factor when dealing with floats? etc...

  • MAXDOP Setting with an EVEN number will outperform ODD number. Is there anything that proves this?

    Hi All,
    MAXDOP Setting with an EVEN number will outperform ODD number. If any of you have any data points, please share.
    NASTY RUMORS ABOUT MAXDOP

    I do not think there is any relations between specifying even and odd numbers in MAXDOP... What are you trying to achieve?
    http://sqlblog.com/blogs/adam_machanic/archive/2010/05/28/sql-university-parallelism-week-part-3-settings-and-options.aspx
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Odd even number and Boolean indicator

    Hi all,
    For example, I have these numbers from 0 to 112233. It will start counting from 0 and shown it on an output indicator. When it is even number (0,2 or 4,...) the Boolean indicator will become false, but when it is odd number (1,3 or,...) the Boolean indicator will become true.
    I'd like to ask if it is possible to detect the values changing in output indicator when it start counting numbers from 0, and then the Boolean indicator will become false or true depending on even or odd number shown on an output indicator? How can I do that?
    Thank you!

    johnsold wrote:
    It may not be that much faster. In the little test VI Q&R takes 581 ms for 10^8 iterations while AND takes 503 ms. That is 78 ps difference. Hardly enough time for a coffee break. Unless you drink really fast.
    Yes, both are "fast enough" for all practical purpose. Even thought they are nealy identical in speed, the Q&R shows more variability in execution time (10% variability), while the AND is singificantly more stable (>1% variability).
    (Make sure you disable debugging for a 10x speedup overall)
    It also seems that the AND code folds better. If we change the control to a diagram constant, the AND version speeds up by a factor of two, even though no folding is shown anywhere inside the sequence structure. I have no idea what that means.
    LabVIEW Champion . Do more with less code and in less time .

  • Check whether value in a field is odd or even

    Hi folks,
    I have some value in a field 'count'. I want to check if the value in that field is even or not. I need to put a IF loop saying that if the value in 'count' is even then execute the loop. How can I do this.
    I appreciate the efficient method to check this. Thanks
    Waiting.............

    You can do something like this.
    report zrich_0002 .
    data: i type i value 48.
    data: remainder type i.
    remainder = i mod 2.
    if remainder = 0.
      write:/ 'This is an even number'.
    else.
      write:/ 'This is an odd number'.
    endif.
    Ooops, Abdul beat me to it.
    Regards,
    Rich Heilman
    Message was edited by: Rich Heilman

  • "generate subset" in script gives error if even number

    I am try to generate with a scipt using a PXI6551.  In the generate subset command if it is a EVEN number such as below (gree) subset(0,17) it gives the error below (red).  If it is an ODD number it works.  Is this a bug, normally you would need an even number of samples to be able to generate but with the script it seems to give the error if there is an even number?
    Thanks,
    Brian
    script myScript
       repeat 1
          Generate PRBS
       end repeat
       Generate PRBS subset(0,17) <-gives error   (0,18) does not give error
    script
    Error -1074115617 occurred at niHSDIO Write Script.vi
    Possible reason(s):
    Driver Status:  (Hex 0xBFFA4BDF) DAQmx Error -200032 occurred:
    Subset length specified is not valid.
    Change the subset length to be longer than zero samples and a multiple of the alignment quantum.
    Line Number: 5
    Position in Line: 18
    Subset Length: 17
    Alignment Quantum: 2
    Status Code: -200032
    Message Edited by BrianPack on 09-29-2005 04:29 PM

    Brian,
    The format (x,y) means y samples starting at position X and therefore when you specify (0,17) you would still generate 17 samples but starting at position 0. Whereas when specifying (1,17) you would generate STILL 17 samples but starting at position 1.  Therefore, in either case, you are still asking to generate an odd number of samples. Hope this helps.
    Ayman K

  • Odds and evens

    Hi,
    How can i determine when a number is odd or even?.
    Rgds,
    Jose

    hi,
    Just divide by 2, and check the remainder.
    report ztest.
    data:
          rem type p decimals 2,
          val type i value 657.
    rem = ( val mod 2 ).
    if rem = 0.
      write:/ 'Even'.
    else.
      write:/ 'Odd'.
    endif.
    Hope this helps !!!
    Cheers
    Alfred

  • Different margin for odd and even pages

    Hi there,
    I am writing a book which will be printed in 2 sided paper. Therefor I will need different margin (left and right) for the odd and even pages.
    How is it possible in Pages? I am using Pages 5.2 (1860).
    Thank you.
    Sebastian.

    Indesign & Xpress are professional DTP applications. They can layout pages in any order you can imagine with custom margins. They are also complex to learn & expensive in comparison to Pages.
    There is a trial of Indesign IIRC…
    https://www.adobe.com/uk/products/indesign.html
    Quark also has a trial too…
    http://www.quark.com
    I expect there may be cheaper 'layout' software that is capable of arranging facing pages correctly (possibly from a single pages PDF export from Pages), but I just avoid apps like Pages if I need a finer level of output control.

  • Count if odd or even

    What formula should i use to count the number of cells that are odd, or even?

    Hi Jerrold,
    It's like this table, with more lines...
    ODD Count
    A
    B
    C
    D
    F
    G
    H
    I
    K
    5
    5
    3
    6
    7
    8
    5
    13
    22
    12
    4
    3
    25
    6
    8
    19
    18
    21
    4
    2
    4
    12
    13
    20
    17
    3
    21
    8
    22
    2
    Thanks again

  • Odd and even rotating pages by file name

    Hi all,
    Hoping someone can help me trouble shoot my script below.
    The aim is to determined if the last two digits of the file name are odd or even and then rotate the file accordingly.
    I have been able to get the page rotation work by it's self but it seems to do nothing at all when trying to get the last two digits of the filename and use them as the variable "pgNum".
    Files will be named using the following convention....
    aa-02-02.pdf
    Thank you in advance for you help.
    =======================================================================================
    var re = /.*\/|\.pdf$/ig;
    var filename = this.path.replace(re,"");;
    var pgNum = filename.substring(-2);
    try {
        if(pgNum % 2) {
            var crtpagerotate = this.getPageRotation({nPage:i});
            this.setPageRotations({nStart: i, nEnd: i, nRotate:(270+crtpagerotate)%360});
        else {
            var crtpagerotate = this.getPageRotation({nPage:i});
            this.setPageRotations({nStart: i, nEnd: i, nRotate:(90+crtpagerotate)%360});
    catch (e)
        console.println("Batch Aborted: " + e )

    Try this:
    var re = /\.pdf$/i;
    var filename = this.documentFilename.replace(re, "");
    var pgNum = +filename.slice(-2);

  • Odd and Even Headers in Pages 5

    I think this has been asked before, but is it possible to making different odd and even-paged headers in Pages 5? I can't figure it out.

    You can take this to be the answer for most things Pages 5…
    … No!
    Use Pages '09 instead.
    Peter

  • FINDING MEDIAN FOR AN ARRAY OF INTS WITH EVEN NUMBER OF VALUES

    okie dokie fellas i know this has got to be easy but i hjave been sittin at my comp forever workin on projects that are due and my head isn't all there anymore...could someone please clue me in on how im supposed to write the logic to find the median of an array of integers if the array contains an even number of values...I know I have to average the 2 values on either side but i cant figure it out at all...sorry i know its dumb but thnaks to anyone who helps
    package pgm3deClercqMatt;
    * @author Owner
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    import java.sql.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.text.*;
    public class ExamStatistics
         public static void main(String[] args)
              DbConnection db = new DbConnection("pgm3");
              boolean moreRecords;
              String query = "SELECT * FROM pgm3Data ORDER BY ExamGrade";
              ResultSet rs = db.processQuery(query);
              int nbrGrades = 0;
              ResultSetMetaData rsmd = null;
              try
                   rsmd = rs.getMetaData();
              catch(SQLException sqlex)
                   JOptionPane.showMessageDialog(null, "SQLException getting ResultSet data or metadata");
                   System.exit(0);
              int s[] = new int[200];
              DecimalFormat decimal = new DecimalFormat("#,##0.00");
              int n = 0, aboveNinety = 0, numberAboveNinety = 0;
              double sum = 0, avgGrade = 0, medianGrade = 0;
              try
                   moreRecords = rs.next();
                   if(!moreRecords)
                        JOptionPane.showMessageDialog(null, "pgm3Data Result Set is Empty.");
                        System.exit(0);
                   while(moreRecords)
                        s[n] = rs.getInt(1);
                        n++;
                        moreRecords = rs.next();
                   }// end of while loop
                   System.out.println("n = " + n);
                   System.out.println("s[0]= " + s[0]);
                   System.out.println("s[n-1]= " + s[n-1]);
                   //FIND AVERAGE OF ARRAY
                   for(int j=0; j<n; ++j)
                        sum += s[j];
                        avgGrade = sum/n;
                   //FIND NUMBER OF GRADES ABOVE OR EQUAL TO 90
                   for(int j=0; j<n; ++j)
                        if(s[j]>=90)
                             numberAboveNinety++;
                   //FIND MEDIAN EXAM GRADE
                   for(int j=0; j<n ; ++j)
                        if(Math.abs(medianGrade - Math.floor(medianGrade))<1.e-10)
                              medianGrade = s[(j+1)/2];
                        else
                             medianGrade =    <HERE IS WHERE THE PROB IS
              }// end of try block
              catch(SQLException sqlex)
                   JOptionPane.showMessageDialog(null, " SQLException getting ResultSet data or metadata");
                   System.exit(0);
              String output = "";
              output = "Number of Exam Grades: " + n;
              output += "\nHighest Exam Grade: " + maxOfArray(s, n) + "\nLowest Exam Grade: " + minOfArray(s, n)
                        + "\nAverage Grade: " + decimal.format(avgGrade) + "\nNumber of exam grades above 90: "
                        + numberAboveNinety + "\nMedian Exam Grade: " + medianGrade;
              JOptionPane.showMessageDialog(null, output);
              System.exit(0);
         }// end of main
         static int maxOfArray(int z[], int n)
              int j, max = z[0];
              for(j=1; j<n; ++j)
                   if(z[j]>max)
                        max = z[j];     
              return max;
         static int minOfArray(int z[], int n)
              int j, min = z[0];
              for(j=1; j<n; ++j)
                   if(z[j]<min)
                        min = z[j];     
              return min;
    }// end of ExamStatistics
    class DbConnection
         //     class DbConnection creates and manages the db connection,
         //     processes queries, and returns result sets for processing
         private Connection connection = null;
         private String url="jdbc:odbc:";
         private Statement statement;
         private String username = "";
         private String password = "";
         private ResultSet rs;
         private int nbrResultSets = 0;
         //     Constructor Argument is the registered name of the database
         DbConnection(String dbName)
              try
              {// load driver to allow connection to database
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   connection = DriverManager.getConnection ((url+dbName), username, password );
              catch (ClassNotFoundException cnfex)
                   fatalError("ClassNotFoundException on connection attempt");
                   System.exit(0);
              catch (SQLException sqlex )
                   fatalError("SQLException -- Unable to Connect to db");
                   System.exit(0);
         } // end of constructor
         ResultSet processQuery(String query)
         //     process a single SQL query and return the resulting data set
              rs = null;
              try
                   statement = connection.createStatement();
                   rs = statement.executeQuery(query);
              catch (SQLException sqlex)
                   fatalError("SQLException on query or processing");
              return rs;
         void endConnection()
              try
                   connection.close();
              catch (SQLException e)
                   fatalError("SQLException on attempt to close connection");
         //     simple local fatal error handler
         private void fatalError(String msg)
              JOptionPane.showMessageDialog(null,msg);
              System.exit(0);
    } // end of class DbConnection

    sorry to anyone who thinks what i'm doing is a joke
    first of all i'm a student and secondly i'm taking
    java in a summer session so things don't get
    explained as well as they should. And how is this our problem?
    I'm doing the best
    i can. The for loop was because the array that I
    defined to hold 200 values was being filled by a
    database with a supposed unknown number of values but
    less than 200 so i waslooping through to get each
    value and put it in order and the conditional
    statement was supposed to test to see if the incoming
    median was an integer and was in the final write-up
    put into it's own boolean method returning false if
    there was no median and you needed to take the
    average of the next lowest and highest values. BThere's always a median. The definition I sent you tells you what it is.
    But
    thnak you very much to the people that actually help
    on here and don't try to bash people who have put
    effort into writing their code, however shitty it may
    look to them. You can't control what people say about your stuff. Everyone who criticizes your work isn't making a personal attack. They're telling you something that you should be learning from. Your problem is that you can't separate yourself from your work.
    No one knows absolutely everything and
    people who decide to talk down on others when they
    are using this forum as a last resort need to grow
    up.Grow up? That's what you need to do. If you think for a moment that you'll never be criticized once you leave that ivory tower you're sadly mistaken. You need to figure out how to separate yourself from your code.
    %

Maybe you are looking for

  • Functionality loss when 'Using Query Bind Variables in Advanced Search

    Regarding: 'Using Query Bind Variables in Quick or Advanced Search' The functionality to do the following is lost when I use bind variables in the Advanced Search: "Result matches all conditions" "Result matches any condition" "Case Sensitive?" Is th

  • Adobe Connect 8 - Recordings

    Hello, I need help understanding the Universal Voice Solution or a comparable substitute for a situation I am in with adobe connect 8.  I am trying to basically learn how I can sync up an audio recording from a teleconference with a web cast recordin

  • Crash when update Dreamweaver 8 to 8.0.1 and 8.0.2 in MAC

    Crash when update Dreamweaver 8 to 8.0.1 and 8.0.2 in MAC PowerMac G5 Quad with Mac OS 10.4.7

  • Block third party tools in oracle

    hello ! everyone can anyone tell me how to block toad from accessing data in oracle database presently i am using oracle 9 release 2

  • Palm phone call record

    I am no longer able to access the phone log on my Treo 650 by pushing the send buttom twice. the automatically generated incoming and outgoing phone log seems to have vanished. Can anyone offer some asssistance please? Post relates to: Treo 650 (Unlo