Converting a string of numbers into an array of booleans

For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?

billko wrote:
Hooovahh wrote:
billko wrote:
Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier. 
I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.
LOL maybe that was one of the objectives of the homework. 
To be fair it sounds like there is more work that is needed.  A new user of LabVIEW will have a hard time figuring out how to process each character one at a time when it isn't in an array.  
It's just that most people (me at least) stopped thinking about division with quotient and remainder after basic algebra.  I then of course changed my way of thinking when I used LabVIEW.  Still most of the time when you use division you want to know the fractional part as a decimal.  Thinking this way makes the problem more difficult then it needs to be.
Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

Similar Messages

  • Feeding numbers into an Array

    Hi, I want to feed numbers into an array but its only using the first element. In my vi users can enter a number and this number needs to be then stored in an array. Any help would be welcome. Thanks

    like this maybe?
    Of course you would replace the random number with a control and use an event structure to spin the loop only if the input is changed by the user, for example.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    AddNumbers.png ‏2 KB

  • PL/SQL function to read a string of characters into an array

    I was wondering if there is an easier way than using the substr function multiple times. Here is the example:
    Suppose you have a varchar2 variable that contains the word 'Apple'. The function should take it and produce an array. We would invoke it like this:
    <what data structure?> a := stringunpackerfunction(x);
    // x is the varchar2 containing 'Apple'.
    The resulting a would be such that a[0] is 'A', a[1] is 'p', a[2] is 'p', a[3] is 'l' and a[4] is 'e'.
    If there is no direct function to do this in a single invocation, is there a function to simply read a string of characters and return 'the next character'?
    Thanks,
    Regards,
    Srini

    There is a procedure out there called PS_PARSE which takes a string and converts to an array provided with an identified separator. Works for us pretty well.
    I just grabbed this off of google. I am presuming this should work fine. It has been sometime since we implemented ours that I forget if there were any additional modifications that we made. I think there was one regarding the size of the string that could be handled. I forget precisely. Anyways... take a peek at it. Its makes things easy in that your logic is pretty streamlined.
    Barry C
    http://www.myoracleportal.com
    create or replace PACKAGE PS_Parse
    IS
         || PL/SQL table structures to hold atomics retrieved by parse_string.
         || This includes the table type definition, a table (though you can
         || declare your own as well, and an empty table, which you can use
         || to clear out your table which contains atomics.
         TYPE atoms_tabtype IS TABLE OF VARCHAR2(60) INDEX BY BINARY_INTEGER;
         atoms_table atoms_tabtype;
         empty_atoms_table atoms_tabtype;
         || The standard list of delimiters. You can over-ride these with
         || your own list when you call the procedures and functions below.
         || This list is a pretty standard set of delimiters, though.
         std_delimiters VARCHAR2 (50) := ' !@#$%^&*()-_=+\|`~{{]};:''",<.>/?';
         /* Display contents of table using DBMS_OUTPUT */
         PROCEDURE display_atomics
              (table_in IN atoms_tabtype, num_rows_in IN NUMBER);
         || The parse_string procedure: I provide two, overloaded definitions.
         || The first version puts all atomics into a PL/SQL table and would
         || be used in a PL/SQL Version 2 environment. The second version places
         || all atomics into a string, separating each atomic by a vertical bar.
         || (My code does NOT do any special handling when it finds a "|" in
         || the string. You have to deal with that when you extract the atomics.
         ||
         || See the program definition for more details on other parameters.
         PROCEDURE parse_string
              (string_in IN VARCHAR2,
              atomics_list_out OUT atoms_tabtype,
              num_atomics_out IN OUT NUMBER,
              delimiters_in IN VARCHAR2 := std_delimiters);
         PROCEDURE parse_string
              (string_in IN VARCHAR2,
              atomics_list_out IN OUT VARCHAR2,
              num_atomics_out IN OUT NUMBER,
              delimiters_in IN VARCHAR2 := std_delimiters);
         /* Count the number of atomics in a string */
         FUNCTION number_of_atomics
              (string_in IN VARCHAR2,
              count_type_in IN VARCHAR2 := 'ALL',
              delimiters_in IN VARCHAR2 := std_delimiters)
         RETURN INTEGER;
         /* Return the Nth atomic in the string */
         FUNCTION nth_atomic
              (string_in IN VARCHAR2,
              nth_in IN NUMBER,
              count_type_in IN VARCHAR2 := 'ALL',
              delimiters_in IN VARCHAR2 := std_delimiters)
         RETURN VARCHAR2;
    END PS_Parse;
    create or replace PACKAGE BODY PS_Parse
    IS
    /* Package variables used repeatedly throughout the body. */
    len_string     NUMBER;
    start_loc     NUMBER;
    next_loc     NUMBER;     
    || Since the PUT_LINE procedure regards a string of one or more
    || spaces as NULL, it will not display a space, which is in
    || PS_Parse a valid atomic. So I save a_blank in the PL/SQL
    || table instead of the space itself.
    a_blank CONSTANT VARCHAR2(3) := '" "';
    /*--------------------- Private Modules ---------------------------
    || The following functions are available only to other modules in
    || package. No user of PS_Parse can see or use these functions.
    FUNCTION a_delimiter
    (character_in IN VARCHAR2,
    delimiters_in IN VARCHAR2 := std_delimiters)
    RETURN BOOLEAN
    || Returns TRUE if the character passsed into the function is found
    || in the list of delimiters.
    IS
    BEGIN
    RETURN INSTR (delimiters_in, character_in) > 0;
    END;
    FUNCTION string_length (string_in IN VARCHAR2)
    RETURN INTEGER
    IS
    BEGIN
    RETURN LENGTH (LTRIM (RTRIM (string_in)));
    END;
    FUNCTION next_atom_loc
    (string_in IN VARCHAR2,
    start_loc_in IN NUMBER,
    scan_increment_in IN NUMBER := +1)      
    || The next_atom_loc function returns the location
    || in the string of the starting point of the next atomic (from the
    || start location). The function scans forward if scan_increment_in is
    || +1, otherwise it scans backwards through the string. Here is the
    || logic to determine when the next atomic starts:
    ||
    ||          1. If current atomic is a delimiter (if, that is, the character
    ||               at the start_loc_in of the string is a delimiter), then the
    ||               the next character starts the next atomic since all
    ||               delimiters are a single character in length.
    ||
    ||          2. If current atomic is a word (if, that is, the character
    ||               at the start_loc_in of the string is a delimiter), then the
    ||               next atomic starts at the next delimiter. Any letters or
    ||               numbers in between are part of the current atomic.
    ||
    || So I loop through the string a character at a time and apply these
    || tests. I also have to check for end of string. If I scan forward
    || the end of string comes when the SUBSTR which pulls out the next
    || character returns NULL. If I scan backward, then the end of the
    || string comes when the location is less than 0.
    RETURN NUMBER
    IS
    /* Boolean variable which uses private function to determine
    || if the current character is a delimiter or not.
    was_a_delimiter BOOLEAN :=
    PS_Parse.a_delimiter (SUBSTR (string_in, start_loc_in, 1));     
    /* If not a delimiter, then it was a word. */
    was_a_word BOOLEAN := NOT was_a_delimiter;
    /* The next character scanned in the string */
              next_char VARCHAR2(1);
    || The value returned by the function. This location is the start
    || of the next atomic found. Initialize it to next character,
    || forward or backward depending on increment.
    return_value NUMBER := start_loc_in + scan_increment_in;
    BEGIN
    LOOP
    -- Extract the next character.
    next_char := SUBSTR (string_in, return_value, 1);
    -- Exit the loop if:
    EXIT WHEN
    /* On a delimiter, since that is always an atomic */
    a_delimiter (next_char)
    OR
    /* Was a delimiter, but am now in a word. */
    (was_a_delimiter AND NOT a_delimiter (next_char))
    OR
    /* Reached end of string scanning forward. */
    next_char IS NULL
    OR
    /* Reached beginning of string scanning backward. */
    return_value < 0;
    /* Shift return_value to move the next character. */
    return_value := return_value + scan_increment_in;
    END LOOP;
    -- If the return_value is negative, return 0, else the return_value
    RETURN GREATEST (return_value, 0);
    END;
    PROCEDURE increment_counter
    (counter_inout IN OUT NUMBER,
    count_type_in IN VARCHAR2,
    atomic_in IN CHAR)
    || The increment_counter procedure is used by nth_atomic and
    || number_of_atomics to add to the count of of atomics. Since you
    || can request a count by ALL atomics, just the WORD atomics or
    || just the DELIMITER atomics. I use the a_delimiter function to
    || decide whether I should add to the counter. This is not a terribly
    || complex procedure. I bury this logic into a separate module,
    however,
    || to make it easier to read and debug the main body of the programs.
    IS
    BEGIN
    IF count_type_in = 'ALL' OR
    (count_type_in = 'WORD' AND NOT a_delimiter (atomic_in)) OR
    (count_type_in = 'DELIMITER' AND a_delimiter (atomic_in))
    THEN
    counter_inout := counter_inout + 1;
    END IF;
    END increment_counter;
    /* ------------------------- Public Modules -----------------------*/
    PROCEDURE display_atomics
    (table_in IN atoms_tabtype, num_rows_in IN NUMBER)
    || Program to dump out contents of table. Notice I must also pass in
    || the number of rows in the table so that I know when to stop the
    || loop. Otherwise I will raise a NO_DATA_FOUND exception. For a more
    || elaborate display_table module, see Chapter 7 on PL/SQL tables.
    IS
    BEGIN
    FOR table_row IN 1 .. num_rows_in
    LOOP
    DBMS_OUTPUT.PUT_LINE (NVL (table_in (table_row), 'NULL'));
    END LOOP;
    END;
    PROCEDURE parse_string
    (string_in IN VARCHAR2,
    atomics_list_out OUT atoms_tabtype,
    num_atomics_out IN OUT NUMBER,
    delimiters_in IN VARCHAR2 := std_delimiters)
    || Version of parse_string which stores the list of atomics
    || in a PL/SQL table.
    ||
    || Parameters:
    ||          string_in - the string to be parsed.
    ||          atomics_list_out - the table of atomics.
    ||          num_atomics_out - the number of atomics found.
    ||          delimiters_in - the set of delimiters used in parse.
    IS
    BEGIN
    /* Initialize variables. */
    num_atomics_out := 0;
    len_string := string_length (string_in);
    IF len_string IS NOT NULL
    THEN
    || Only scan the string if made of something more than blanks.
    || Start at first non-blank character. Remember: INSTR returns 0
    || if a space is not found. Stop scanning if at end of string.
    start_loc := LEAST (1, INSTR (string_in, ' ') + 1);
    WHILE start_loc <= len_string
    LOOP
    || Find the starting point of the NEXT atomic. Go ahead and
    || increment counter for the number of atomics. Then have to
    || actually pull out the atomic. Two cases to consider:
    ||          1. Last atomic goes to end of string.
    ||          2. The atomic is a single blank. Use special constant.
    ||          3. Anything else.
    next_loc := next_atom_loc (string_in, start_loc);
    num_atomics_out := num_atomics_out + 1;
    IF next_loc > len_string
    THEN
    -- Atomic is all characters right to the end of the string.
    atomics_list_out (num_atomics_out) :=
    SUBSTR (string_in, start_loc);
    ELSE
    || Internal atomic. If RTRIMs to NULL, have a blank
    || Use special-case string to stuff a " " in the table.
    atomics_list_out (num_atomics_out) :=
    NVL (RTRIM (SUBSTR (string_in,
    start_loc, next_loc-start_loc)),
                                       a_blank);
    END IF;
    -- Move starting point of scan for next atomic.
    start_loc := next_loc;
    END LOOP;
    END IF;
    END parse_string;
    PROCEDURE parse_string
    (string_in IN VARCHAR2,
    atomics_list_out IN OUT VARCHAR2,
    num_atomics_out IN OUT NUMBER,
    delimiters_in IN VARCHAR2 := std_delimiters)
    || The version of parse_string which writes the atomics out to a packed
    || list in the format "|A|,|C|". I do not repeat any of the comments
    || from the first iteration of parse_string.
    IS
    BEGIN
    /* Initialize variables */
    num_atomics_out := 0;
    atomics_list_out := NULL;
    len_string := string_length (string_in);
    IF len_string IS NOT NULL
    THEN
    start_loc := LEAST (1, INSTR (string_in, ' ') + 1);
    WHILE start_loc <= len_string
    LOOP
    next_loc := next_atom_loc (string_in, start_loc);
    num_atomics_out := num_atomics_out + 1;
    IF next_loc > len_string
    THEN
    atomics_list_out := atomics_list_out || '|' ||      
    SUBSTR (string_in, start_loc);
    ELSE
    atomics_list_out :=
    atomics_list_out || '|' ||      
    NVL (RTRIM (SUBSTR (string_in,
    start_loc, next_loc-start_loc)),
                                       a_blank);
    END IF;
    start_loc := next_loc;
    END LOOP;
    /* Apply terminating delimiter to the string. */
    atomics_list_out := atomics_list_out || '|' ;
    END IF;
    END parse_string;
    FUNCTION number_of_atomics
    (string_in IN VARCHAR2,
    count_type_in IN VARCHAR2 := 'ALL',
    delimiters_in IN VARCHAR2 := std_delimiters)
    RETURN INTEGER
    || Counts the number of atomics in the string_in. You can specify the
    || type of count you want: ALL for all atomics, WORD to count only the
    || words and DELIMITER to count only the delimiters. You can optionally
    || pass your own set of delimiters into the function.
    IS
    return_value INTEGER := 0;
    BEGIN
    /* Initialize variables. */
    len_string := string_length (string_in);
    IF len_string IS NOT NULL
    THEN
    || This loop is much simpler than parse_string. Call the
    || next_atom_loc to move to the next atomic and increment the
    || counter if appropriate. Everything complicated is shifted into
    || sub-programs so that you can read the program "top-down",
    || understand it layer by layer.
    start_loc := LEAST (1, INSTR (string_in, ' ') + 1);
    WHILE start_loc <= len_string
    LOOP
    increment_counter (return_value, UPPER (count_type_in),
    SUBSTR (string_in, start_loc, 1));
    start_loc := next_atom_loc (string_in, start_loc);
    END LOOP;
    END IF;
    RETURN return_value;
    END number_of_atomics;
    FUNCTION nth_atomic
    (string_in IN VARCHAR2,
    nth_in IN NUMBER,
    count_type_in IN VARCHAR2 := 'ALL',
    delimiters_in IN VARCHAR2 := std_delimiters)
    RETURN VARCHAR2
    || Find and return the nth atomic in a string. If nth_in is greater
    || the number of atomics, then return NULL. If nth_in is negative the
    || function counts from the back of the string. You can again request
    || a retrieval by ALL atomics, just the WORDs or just the DELIMITER.
    || So you can ask for the third atomic, or the second word from the end
    || of the string. You can pass your own list of delimiters as well.
    IS
    /* Local copy of string. Supports up to 1000 characters. */
    local_string VARCHAR2 (1000) :=
    LTRIM (RTRIM (SUBSTR (string_in, 1, 1000)));
    /* Running count of atomics so far counted. */
    atomic_count NUMBER := 1;
    /* Boolean variable which controls the looping logic. */
    still_scanning BOOLEAN :=
    local_string IS NOT NULL AND nth_in != 0;
    /* The amount by which I increment the counter. */
    scan_increment INTEGER;
    /* Return value of function, maximum length of 100 characters. */
    return_value VARCHAR2 (100):= NULL;
    BEGIN
    IF nth_in = 0
    THEN
    /* Not much to do here. Find 0th atomic? */
    RETURN NULL;
    ELSE
    /* Initialize the loop variables. */
    len_string := string_length (local_string);
    IF nth_in > 0
    THEN
    /* Start at first non-blank character and scan forward. */
    next_loc := 1;
    scan_increment := 1;
    ELSE
    /* Start at last non-blank character and scan backward. */
    next_loc := len_string;
    scan_increment := -1;
    END IF;
    /* Loop through the string until the Boolean is FALSE. */
    WHILE still_scanning
    LOOP
    /* Move start of scan in string to loc of last atomic. */
    start_loc := next_loc;
    /* Find the starting point of the next atomic. */
    next_loc      :=
    next_atom_loc (local_string, start_loc, scan_increment);
    /* Increment the count of atomics. */
    increment_counter
    (atomic_count,
    UPPER (count_type_in),
    SUBSTR (local_string, start_loc, 1));
    || Keep scanning if my count hasn't exceeded the request
    || and I am neither at the beginning nor end of the string.
    still_scanning :=
    atomic_count <= ABS (nth_in) AND
    next_loc <= len_string AND
    next_loc >= 1;
    END LOOP;
    || Done with the loop. If my count has not exceeded the requested
    || amount, then there weren't enough atomics in the string to
    || satisfy the request.
    IF atomic_count <= ABS (nth_in)
    THEN
    RETURN NULL;
    ELSE
    || I need to extract the atomic from the string. If scanning
    || forward, then I start at start_loc and SUBSTR forward.
    || If I am scanning backwards, I start at next_loc+1 (next_loc
    || is the starting point of the NEXT atomic and I want the
    || current one) and SUBSTR forward (when scanning in
    || reverse, next_loc comes before start_loc in the string.
    IF scan_increment = +1
    THEN
    RETURN
    SUBSTR (local_string, start_loc, next_loc - start_loc);
    ELSE
    RETURN
    SUBSTR (local_string, next_loc+1, start_loc - next_loc);
    END IF;
    END IF;
    END IF;
    END nth_atomic;
    END PS_Parse;
    /

  • [Oracle 8i] How to convert a string (time stamp) into a date?

    I'm having difficulty figuring out how to convert a time stamp string into a date (or possibly a number).
    The time stamp is 20 positions, character (NOT NULL, CHAR(20))
    in the format: YYYYMMDDHHMMSSUUUUUU
    where Y = Year, M = Month, D = Day, M = Minutes, S = Seconds, and U = Microseconds
    The reason I want to convert this is so that I can compare one time stamp to another (i.e. I want to be able to find the MIN(timestamp), MAX(timestamp), and do inequality comparisons).
    Is this at all possible?
    Thanks in advance for help on this!

    Hi,
    As Damorgan said, if all you want to do is find which is the earliest or latest, then you can just compare the strings: they happen to be in a format where that works.
    If you need to do other things, such as compare them to today's date, or see the difference between two of your rows in days, then you have to convert them to DATEs. (There's no point in converting them to NUMBERs).
    A new data type, TIMESTAMP, which handles fractions of a second, was introduced in Oracle 9.
    Since you're using Oracle 8 (according to your subject line), you either have to
    (1) ignore the microseconds, or
    (2) use a separate NUMBER column for the microseconds.
    Either way, use TO_DATE to convert the first 14 characters to a DATE:
    TO_DATE ( SUBSTR (txt, 1, 14)
            , 'YYYYMMDDHH24MISS'
            )where txt is your CHAR column.
    To convert the microseconds to a number (between 0 and 999999):
    TO_NUMBER (SUBSTR (txt, 15))

  • Can't convert my String to numbers

    Hi!
    I'm trying to convert my received data to numbers in actionscript in Flex.
    I want to use the numbers that I get in a calculation.
    The function where the data ("Svar") in received and saved in a string looks like this:
    Svar.htmlText = event.result.toString();
    And this is the calculation that I want to do:
    var r:Number = Number(Svar)/2.1;
    var newheight:Number = 420 * r;
    var newwidth:Number = 162 * r;
    resizeLarge.widthTo = newwidth;
    resizeLarge.heightTo = newheight;
    resizeLarge.duration=750;
    I've checked the calculation and it works so it must be something wrong with the
    "Svar" data.
    I'd be really grateful if someone could help me!

    Hi,
    You are doing something wrong with the calculation in the below line of code.
    var r:Number = Number(Svar)/2.1;
    Here what does Svar corresponds to....Is it a variable or a Labeel control....?
    I think Svar is some kind of a Label or Text control since in your code you have used "htmlText: attribute with the "Svar" as shown below.
    Svar.htmlText = event.result.toString();
    So in your calculation also you need to use the same ...I mean ...text property as shown below..
    var r:Number = Number(Svar.text)/2.1;
    Dont use Svar.htmlText  in calculation as it may give include unnecessary htmltags and your conversion from string to Number fails.
    Hope now the things are clear...If you still have any dobt let me know.
    If this post answers your question or helps, please kindly mark it as such.
    Thanks,
    Bhasker Chari

  • How to converts this string to a new character array???

    I have string that get from g.getDirectory();
    that string is "D:\Songs\Judas Priest"
    and I want to convert to charArray[][] = {{"D",":","\","S","o","n",.....}};
    how can I do it??
    :'(

    I have ploblem again :'(
    indeed I want to change string
    D:\Songs\Judas Priest
    to
    D:/Songs/Judas Priest
    I do this for upload my picture to program by directory
    but when I use getDirectory();
    It only save "D:\Songs\Judas Priest"
    so I must change "\" to "/"
    I think I must use "for" and check if it found "\" it will be change to "/"
    but I don't know how to write?
    public String[][] sliceNwrap(String str){
         dir[0] = new String[str.length()];
         for(int ndx=0;ndx<str.length();ndx++){
              if(str.substring(ndx, ndx+1)=="\\"){
                   dir[0][ndx]= "/";
              else{
                   dir[0][ndx] = str.substring(ndx, ndx+1);
         return dir;
    It still "D:\Songs\Judas Priest" :'( help me plz

  • Convert the string-encoded uid into its original object form

    I have written the uid string into a database and when I need it again in my code I need to rebuild the UID from the string in the db, as it was before.
    Does somebody know how this can be done with java?
    Thx in advance

    I have written the uid string into a database and when I need it again in my code I need to rebuild the UID from the string in the db, as it was before.
    Does somebody know how this can be done with java?
    Thx in advance

  • How do I convert an image file into an array?

    I am using LabVIEW v.6.0.2
    I have no NI IMAQ device or IMAQ card, also no Vision
    The image file I have can be saved as a file containing numbers relating to the picels. I want to put these numbers into an array and plot a cross section intensity chart ( I am investigating young's double slits experiment and want to see the interference fringes in graphical form).

    I'm not sure what you're asking.
    In the GRAPHICS palette, there are READ JPEG file, READ BMP file, and READ PNG file VIs. Choose one and together with DRAW FLATTENED PIXMAP and a PICTURE indicator, you can display a picture with two functions and two wires.
    If you have spreadsheet-type data and import it with READ FROM SPREADSHEET FILE (in the File I/O palette), you can plot that directly to an intensity indicator.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • How to get input from keyboard scanner into an array

    This is probably a very basic question but I'm very new to java..
    My task is to reverse a string of five digits which have been entered using keyboard scanner.
    E.g. - Entered number - 45896
    Output - 69854
    I used the StringBuffer(inputString).reverse() command for this, but i need a more basic method to do this.
    I thought of defining an array of 5
    int[] array = new int [5];
    and then using,
    Scanner scan = new Scanner(System.in);
    to enter the numbers. But I can't figure out how to get the five input numbers into the array.
    If I can do this I can print the array in reverse order to get my result.
    Any other simple method is also welcome.

    Hey thanks for the quick reply,
    But how can I assign the whole five digit number into the array at once without asking to enter numbers separately?
    E.g. - if entered number is 65789
    Assign digits into positions,
    anArray [0] = 6;
    anArray [1] = 5;
    anArray [2] = 7;
    anArray [3] = 8;
    anArray [4] = 9;
    I'm really sorry but I am very new to the whole subject.

  • Single string tag expanded into 100 plc register values

    I found a way to read 100 registers of plc data with a single string tag, if you can guarantee that none of the plc registers are zero. A register value of zero acts like a Null ascii terminator and truncates the string. Define the string tag as 200 bytes and uncheck the text data only box. Use the code in the attached picture to convert the string bytes back into decimal register values.
    Attachments:
    string tag to 100 U16 values.gif ‏2 KB

    Ins't that code exactly the same as typecasting to an U16 Array?
    Message Edited by altenbach on 05-19-2005 07:24 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    CastingU16.gif ‏3 KB

  • Putting input into an array

    I've created a java program with an array of 7 numbers. the first number indicated how many numbers will be entered.
    for ex. 6, 202, 303, 101, 303, 505, 404
    I created an array with the above examples number, and all my methods are working to compute the average, values equal to average, below average and above average.
    However, right now its not quite right because ive entered the numbers into the array manually. What i need to do is take the numbers from the input stream and enter them into the array. How do I do this? Ive been doing so much research and can't figure out how to do it/get it right.
    // shortcut, creates array manualy. need to change this to take the numbers from the standard input stream.
    int[] numbers = { 6, 202, 303, 101, 303, 505, 404};
    // position 0 holds how many numbers there are
    int howMany = 0;
    howMany = numbers[0];
    // average numbers in array
    int numHolder = 0;
    int average = 0;
    int add = 0;
    for (int i = 1; i<numbers.length; i++) {
        add = numbers[i] + add;
        average = add / howMany;
    // number of integers that is less than the average
    int lessThan = 0;
    for (int i=1; i<numbers.length; i++){
        if (numbers[i] <  average) {
            lessThan ++ ;
    // number of integers exactly equal to the average
    int equal = 0;
    for (int i=1; i<numbers.length; i++){
         if (numbers[i] ==  average) {
         equal ++ ;
    // number of integers that greater than the average
    int greaterThan = 0;   
    for (int i=1; i<numbers.length; i++){
        if (numbers[i] <  average) {
            greaterThan ++ ;
    // print the results
    System.out.println("Average Value : " + average + "\n");
    System.out.println("Number of values below the average : " + lessThan);
    System.out.println("Number of values equaling average  : " + equal);
    System.out.println("Number of values above the average : " + greaterThan + "\n");

    BufferedReader buffy = new BufferedReader(new InputStreamReader(System.in));
    String input = buffy.readLine();   
    int num = Integer.parseInt(input);
    array[somenumber] = num;You should have try/catch statements so the program does not let the client enter strings.
    Hope this helped

  • Converting a String to a char

    Hello,
    How to a convert a String object consisting of a single character to a char type. I.e., suppose I have
    String myStr = "a"
    I want to be able to convert myStr to a char for use in a switch case statement. Thanks.
    CoreDummy

    i know I can just convert the String "a" to a char array...but there should be a better way to do this...
    Forever an idiot,
    CoreDumb

  • Can I Bind a Front Panel LED to a specific element in an array of booleans?

    In LabVIEW 2010 I have a string of LEDs. I have and array of boolean values that contain the values that the LEDs should indicate.
    What is the best way to connect the LEDs to elements in the array of booleans?
    Can I Bind a Front Panel LED to a specific element in an array of booleans?
    How is this done?
    Can anyone show sample code?
    Solved!
    Go to Solution.

    Imagine that you have an I/O card that provides 128, 256 or 1024 digital inputs and the requirement is to have an LED on the front panel to represent the state of each digital input. This frequently occurs.
    Wiring that many digital inputs individually is a royal pain and then some !
    It would make sense to have one shared variable as an array of Booleans that represents the status of all inputs and then use data binding instead of wiring each individually. The individually wiring would violate all recommendations on diagram size and fan out.
    Frequently scanned For loops to update all of the LEDS would take alot of CPU time.
    Wouldn't it be MUCH better if PSP could be used to update the LEDs whenever the data changed (as it is supposed to do) ?
    In my case I have a LabVIEW Yaskawa servo driver that provides me information about 16 servo drives that may be connected. I have LEDs on the front panel to represent some of that status for each individual drive. But Yaskawa provides the information on the drives as an array of clusters of information for each drive, which I perform some business logic on and turn into shared array of Booleans to feed the LEDs (and some banks of switches as well).
    Unfortunately LabVIEW does not seem to have any way to bind the LEDs (and Switches) to individual elements in the shared array of Booleans. It is just not that smart. Even with only several banks of 16 LEDs and Switches, wiring them individually using Decimate Array of Index Array functions is a royal pain and makes the block diagrams very large. It would be much worse and almost unreasonable to do if the size of the information was much larger.

  • Is there an easy way to convert a long string into an array?

    I can convert a long string into a 1-d array by parsing and using build array, but I would like to know if there is a function to make this easier.
    For example:
    from/   aaaaaaaabbbbbbbbccccccccdddddddd         (string of ascii)
    to/       an array that is 1-d with each element having eight characters
              aaaaaaaa
              bbbbbbbb
              cccccccc
              dddddddd
    Thank you.
    Solved!
    Go to Solution.

    Try something like this:
    (If you can guarantee that the string length is an integer multiple of 8, you an drop the two triangular modes in the upper left. )
    Message Edited by altenbach on 03-14-2010 06:40 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ChopString.png ‏9 KB

  • Is there a way to type cast an array of strings to numbers and back again?

    I'm working on an application where I want to type cast a string like "power supply" into an array of existing numbers. Then sort the existing numbers, and finally convert the casted numbers back into a string so it can be read by the user. In the attachment, you can see my latest attempt with flatten/unflatten data and the 'convert string to byte array'. I can't seem to make this work. Any ideas?
    Thanks - Paul
    Attachments:
    Paul's Temp scan for components.vi ‏56 KB

    OK, here's a quickie (LabVIEW 7.0).
    Simply get the sort key from the 1D array, then build the table.
    Message Edited by altenbach on 10-27-2006 01:34 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SortedTable.png ‏4 KB
    SortedTable.vi ‏37 KB

Maybe you are looking for