Switch/Case: How to test byte values in hex format

OK, this may be a silly question, but being new to Java, I can't seem to get this to work.
I have a byte value that I want to test in a switch/case statement. The value was assigned to the byte in hexadecimal format. However, testing only works if I use the decimal value of the byte!
What's even stranger: It does work in a simple if/else statement. In my debugging attempts, I discovered this using the following code:
//*temporary debug routine
memoryCells[0] = (byte) 0x86; //LDA
if(memoryCells[0] == (byte) 0x86)
    System.err.println("byte recognized as hexadecimal!");
else
    if(memoryCells[0] == -122)
        System.err.println("byte recognized as decimal!"); So, this works in an ordinary if/else statement, but why doesn't it also work in the complex switch/case statement? Snippet below:
       switch (currentOpcode)
            case (byte) 0x86:
                //*LDA immediate (2 bytes, 2 cycles)
                registerA = b;
                currentOpcode = 0x00;
                cycleCounter = 0;
            break;
        }Thanks in advance for any suggestions...

    public static void main(String[] args) throws Exception {
     byte test = (byte)0x86;
     switch(test)
     case (byte)0x86:
              System.out.println("Success");
          break;
     default:
              System.out.println("ooops");
    }This works for me.
~Tim

Similar Messages

  • How can change numeric value to date format? example value 1070131(CYYMMDD)

    in the datatable can i change numeric value to date format . in database date value is like 1070131 (CYYMMDD). I want to see 31/01/07(DD/MM/YY) or 31 Jan 07 . Is it possible?
    Thanks,

    Did you solve your problem?

  • How to Write a file from hex format to another format

    hi I am trying to create a file (IBM AFP-printer format) from the hex file which i have created after reading that IBM afp file. Now i have to do some changes in that hex file data and store it back to the same format.
    I have tryed storing it using:
    Writer out = new OutputStreamWriter(outputStream,"Cp1252");
    but it is taking hex format only.
    I have checked encoding of afp file by this code
    File inputFile = new File( "C:\\ACode\\new2.afp" ) ;
              FileInputStream inputStream = new FileInputStream(inputFile );
         InputStreamReader in = new InputStreamReader(inputStream);
    System.out.println(in.getEncoding());
    it is showing Cp1252 only.
    But i am unable to store it back to same format
    Thanks

    I don't really know what the IBM APF stream format is, but I suspect that your approach is not right. If you really want to read and write raw hex bytes, then do not use readers and writers; instead use pure streams. The reason is that readers and writers are designed to deal with character-oriented data, and will automatically perform translations on input and output.
    On the other hand, if you could find the correct encoding/decoding software for the IBM format in question, well then readers/writers would be fine, and you could do all of your "internal" work in unicode.

  • How to test if value is NULL?

    What is the syntax to test if a value of a variable is NULL, using an IF -ELSE-ENDIF structure?

    if (value == NULL) Nope, NULL !=null.
    if (value == null)

  • In this case, how would you save values to a file?

    Hi,
    I need your advice. I have a Vi with lots of controls and the user can change many settings.
    If I stop and start the vi again, you'll surely know, all settings are back to default, due to the fact that LabVIEW unfortunately does not allow to make values default programmatically.
    Nevertheless there are many possibilities to save and load the settings. But which one is the best in my case?
    I have boolean buttons, over 60 numeric controls, two file pathes and one numeric array.
    I could write all of them separated by tabs in a text file (see screenshot), and read them back - but this is very laborious and prone to mix-up.
    I tried clustering, but it's not possible due to the array, which I cannot put into a cluster.
    What would be the best and simplest way to accomplish this saving and reading of the settings? What would you recommend?  
    Greetings
    Johannes
    LabVIEW 7.1.
    Windows XP Professional 2002 SP 2
    Intel Core 2 Duo, 2,4 GHz
    Message Edited by candidate on 12-01-2008 10:00 AM

    You could write a VI that set values from a file using VI server. With VI server you get references to all controls and create a list of label.text. When you read the value for "Smierung" you search the index of the reference to that control in the label array and set the value using "Value" property.
    Play around with VI server and control references.
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

  • How to save byte[] value to Oracle table?...

    ... what would be the data type in table for the column? THanks.

    I was thinking doing toString() to convert it to a String to insert to Oracle table. My question is actually would it to be safe to retrieve it later on to compare with anther byte[]? Thanks.

  • How to display currency values in indian format

    hi all,
       When I am displaying Currency values as output , those are displaying in U.S. format (ie.1,234,000.00) , But I need to display those in Indian Rupee format (i.e 12,34,000.00).
    Plz any one can help me that how to display this
    thank you,
    regards
    Hanuma

    Hi Hanuma kumar, please try this code.
    REPORT ZAMOUNT_CONVERSION.
    DATA : RESULT1(20).
    PARAMETERS : NUM TYPE P DECIMALS 2.
    DATA : num2 type STRING.
    DATA :  col_amt(20) type n,"15
             col_b type i,
             num_1(20) type C,"15
             Length type i.
    num_1 = num.
    write : 'default format      :',num.
    uline.
    skip.
    IF ( num >= 999999999 ).
           write num_1 using edit mask 'RR__,__,__,__,______' to col_amt.
           CONDENSE col_amt.
           length = STRLEN( col_amt ).
           if length = 16.
             REPLACE first OCCURRENCE OF ',' in col_amt with space.
             write :/'amount indian format:',col_amt.
           else.
           write :/'amount indian format:',col_amt.
           endif.
    ELSEIF NUM < 999999999 AND NUM >= 9999999.
           write num_1 using edit mask 'RR__,__,__,______' to col_amt.
           condense col_amt .
           length = STRLEN( COL_AMT ).
           if length = 13.
             REPLACE first OCCURRENCE OF ',' in col_amt with space.
             write :/'amount indian format:',col_amt.
           else.
             write :/'amount indian format:',col_amt.
          endif.
    ELSEIF NUM < 9999999  AND NUM >= 99999.
           write num_1 using edit mask 'RR__,__,______' to col_amt.
           condense col_amt .
           length = STRLEN( COL_AMT ).
           write :/'amount indian format:',col_amt.
    ELSEIF NUM < 99999.
       data : dumy(10) type c.
       dumy = num .
       CONDENSE dumy.
       length = STRLEN( dumy ).
         if length <= 6.
           write :/'amount indian format:',num.
           else.
           write num_1 using edit mask 'RR__,______' to col_amt.
           write :/'amount indian format:',col_amt.
          endif.
       ENDIF.
       uline.

  • In Scripts how to print the values in currence format

    Dear abap guru's,
    I am working on Purchase Order Script, copy from the standard script, after that wrote a one perform , in that added one new field to script, but value is printed like this formate : 1000.00, but i want to print 1,000.00 like this currence format. let me know the any solution
    thanks to all
    raj.

    Hi ,
    When you are populating the value in perform instead of assigning the value (using = ) pass it using WRITE TO.
    Like :  WRITE lw_total TO output-value.
    Declare lw_total as currency field.
    Regards,
    Rajitha.

  • How to print a value in text format

    hello,
            I want to print a value for eg. 1083.00 in word like one thousand eighty three only......can anybody tell me is there any function module present in SAP to do same.......<removed by moderator>
    Edited by: Mike Pokraka on Aug 4, 2008 6:42 PM

    Hi hav a luk @ below code,
    REPORT  zmdamountwords.
    TABLES: spell,
                  komk.
    *&      Form  get_amt_words
    *       text
    *      -->AMT        text
    *      -->WORDS      text
    FORM get_amt_words TABLES  in_tab  STRUCTURE itcsy
                               out_tab STRUCTURE itcsy.
      DATA : value1 LIKE bseg-dmbtr.
      DATA : value(18).
      DATA : t_value(18).
      DATA : value_s1(18).
      DATA : value_s2(19),
             value_s3(19),
             value_s4(19),
             rs_str(256),
             len TYPE i,
             words LIKE spell.
      CLEAR : value,value1,t_value.
      READ TABLE in_tab WITH KEY 'KOMK-FKWRT'.
      REPLACE ALL OCCURRENCES OF ',' IN in_tab-value  WITH  space.
      CONDENSE in_tab-value.
      value = in_tab-value.
      value1 = value.
      CALL FUNCTION 'Z_SPELL_AMOUNT_INR'
        EXPORTING
          amount     = value1
        IMPORTING
          rupees_str = rs_str
        EXCEPTIONS
          OTHERS     = 1.
      CONDENSE rs_str.
      READ TABLE out_tab WITH KEY 'RS_STR'.
      IF sy-subrc = 0.
        out_tab-value = rs_str.
        MODIFY out_tab INDEX sy-tabix.
      ENDIF.
    ENDFORM.                    "GET_AMT_WORDS
    Let me know if you have any doubt.
    Reward if useful.
    Warm Regards,
    Mohandoss P.

  • HOW TO USE field value in repeat_fram formate trigger

    i have a field on report layout. i want to use its value in formate trigger to filter the record in which that field value is zero.
    field is number type, getting stock of item. i want if stock of item is zero than it should not display, for this i use formate trigger of repeating frame.
    Thanks yash

    yash_08031983 wrote:
    i have a field on report layout. i want to use its value in formate trigger to filter the record in which that field value is zero.
    field is number type, getting stock of item. i want if stock of item is zero than it should not display, for this i use formate trigger of repeating frame.Hello, yash
    Format trigger is for change the formation of value. Like change the font, make it bold,italic, changes it's colour . Not for filtering.
    If you want to restrict your report not to show Zero(0) value of stock , you have to done it at SQL query. Like, if stock is a database filed you may write
    select .........,....
    from table
    where stock >0Hope this helps.
    If someone response is helpful or correct, please mark it accordingly.

  • Can I test (junit) default case of switch-case statement ?

    Hi,
    I have a class which has switch-case statements and I am trying to junit test with 100% coverage. My switch-case workes based on enum values.
    say my enum values are 1, 2.
    switch(getEnumValues) {
    case 1:
    return "some value";
    case 2:
    return "some value";
    default:
    throw new UnsupportedOperationException("No such enum value supported.");
    I have test case to test the case 1 and 2 but I am not able to test default case. Can anyone please let me know how can I right a junit test case for default case.
    Edited by: TUIJAVADEV on Nov 4, 2008 4:15 PM

    yawmark wrote:
    TUIJAVADEV wrote:
    I have test case to test the case 1 and 2 but I am not able to test default case. Can anyone please let me know how can I right a junit test case for default case.If your enum values are ONE and TWO, and you have cases for both, then there is no "default case". There is nothing to test.
    ~If I'm reading the OP correctly, they're 1 and 2, not ONE and TWO. That is, not values of a Java enum.
    If this is the case, then the easiest way to test the default case is to break the swtich out into a separate, package-accessible method that takes and arg and passes that onto the switch. (There may be variations on this, depending on how your code is structured.)
    However, in a similar vein to what the others are saying, if you already know that you'll only ever have 1 and 2 by the time you get to the switch (maybe because the value comes from an argument to the enclosing method, and you've already unit tested that it appropriately throws an IllegalArgumentException when other values are passed, then there's no need to test the default.
    Finally, though if it is ints 1 and 2, rather than a true enum, why not switch to an enum?

  • In eCATT, How to mention the values as  input parameter during test script

    Hi,
    1. I am just learning eCATT tool. I created a Test Script by recording my transaction. But if i want to execute the recorded transaction with different data then how to store the values.
    2. How to execute my Test Script created in one client to another client of same server. is it just by mentioning the target system or do we have to do anything in anothere client.
    Lakshmi

    Hi
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a0e0ebec-c9da-2910-689e-b1a22a621c7f
    Manoj Shakya.

  • I would like to know how can i compare a switch case 1 and case 2 in C# is it possible to do that? obs i am a begginer :)

    i would like to know how can i compare a switch case 1 and case 2 in C# is it possible to do that? obs i am a begginer :) I tried to do it with search and sort but it did not go well

    let me give you an example if you add a word case 1( lagg ord) how can i compare that word with case 2 words ( in case 2  already exist 5 words)
    here is the my program 
    using System;
    namespace ConsoleApplication1
        class Program
            static void Main(string[] args)
                //Meny
                Console.WriteLine("\n HÄNGA GUBBE\n");
                Console.WriteLine(" 1) Lägg till ord");
                Console.WriteLine(" 2) Lista alla ord");
                Console.WriteLine(" 3) Spela");
                Console.WriteLine(" 4) Avsluta");
                bool utgång = false;
                do
                    int Valet;
                    Console.Write("\n\tVälj 1-4: \n ");
                    try
                        Valet = int.Parse(Console.ReadLine());
                    catch (Exception)
                        Console.WriteLine("Du skriver fel character!\n" +
                            "\nSkriv bara mellan 1 och 4");
                        continue;
                    switch (Valet)
                        case 1:
                            Console.WriteLine("\n lägg ett till ord! ");
                          var input = Console.ReadLine();
                            break;
                        case 2:
                            Console.WriteLine("\n Lista med alla ord :\n");
                            string[] array = { " Lev", " Skratta", " Gledje", " Gråt", " Njut" };
                            Array.Sort<string>(array);
                            foreach (var c in array)
                                Console.WriteLine(c);
                            Console.WriteLine("\n");
                            break;
                        case 3:
                            string guesses, bokstäver;
                            Console.Write("\n Hur många fel får man ha? ");
                            guesses = (Console.ReadLine());
                            Console.WriteLine(" Utmärkt, då spelar vi!\n");
                            Console.WriteLine(" Felgisningar :" + "0/" + guesses);
                            Console.Write(" Gissade bokstäver ");
                            bokstäver = (Console.ReadLine());
                            Console.WriteLine("Aktuellt ord");
                            Console.Write("Gissa bokstav : " + bokstäver + " \n");
                            break;
                        case 4:
                            Console.WriteLine("\n  HEJ DÅ! \n");
                            Console.Beep();
                            utgång = true;
                            break;
                        //avbryter while loopen, avslutar spelet
                } while (!utgång);

  • How to test if remote R/3 system (Receiver) is down in case of Async RFC ?

    Hi Experts,
       How to test if remote R/3 system (Receiver) is down in case of Async RFC call? There is no BPM as well. I have configured an alert category and created a rule in runtime workbench's Alert Configuration for the specific inbound interface.
       I have tried by stopping the channel and also by changing the server name in the communication channel but all in vail. XI still shows message successfully processed.
      Kindly help me
    Thanks
    Gopal

    Hi,
    How to test system down in XI? Kindly help!
    Have answered here as well.
    Meanwhile, you would have an error in the receiver RFC adapter in Comm Channel Monitoring.
    Maybe you change another RFC adapter rather than the one being used in the receiver agreement.
    regards
    Bhavesh

  • How to export test cases into oracle test manager

    hi
    present i am learning this tool help plz
    how to export test cases into oracle test manager
    Edited by: 799636 on Oct 5, 2010 7:11 AM

    Create a script in openScript and save it to a workspace (a shared directory on the OTM server). To add an Oracle OpenScript test to OTM:
    1.Select the Tests tab.
    2.Click the Add button.
    3.Enter a name for the test.
    4.Select Oracle OpenScript in the Type field.
    5.Click Find to display the Select Script dialog box.
    6.Select the Repository and Workspace.
    7.Select the Oracle OpenScript script that you want to add.
    8.Click OK.
    9.Select the owner and priority and enter any descriptive information in the Functionality and Description fields.
    10.Click Save.
    Regards,
    Jamie

Maybe you are looking for