Results 1 to 5 of 5
  1. #1
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    20
    Blog Entries
    1
    Rep Power
    0

    Default converting simple C code to Java

    Hi People,
    I am new to C programming and have very little idea on how to convert this following C code to Java:

    Java Code:
    * (DWORD *) roomcode = * (DWORD *) (roomcode + 1) + ((roomcode[0] & 1) ? 0x00000020:0) + ((roomcode[0] & 2) ? 0x00002000:0)
    + ((roomcode[0] & 4) ? 0x00200000:0) + ((roomcode[0] & 8) ? 0x20000000:0);
    roomcode[4] = 0;
    Supposidily, this above code is doing a mapping of 'TT room code' to 'TRH room code', according to thsi following table:


    TRH room code TT room code Binary Code
    ABCD PABCD 0101 0000
    aBCD AABCD 0100 0001
    AbCD BABCD 0100 0010
    abCD CABCD 0100 0011
    ABcD DABCD 0100 0100
    aBcD EABCD 0100 0101
    AbcD FABCD 0100 0110
    abcD GABCD 0100 0111
    ABCd HABCD 0100 1000
    aBCd IABCD 0100 1001
    AbCd JABCD 0100 1010
    abCd KABCD 0100 1011
    ABcd LABCD 0100 1100
    aBcd MABCD 0100 1101
    Abcd NABCD 0100 1110
    abcd OABCD 0100 1111

    Could someone please give me soem hint on how to convert it to java?

    Thanks.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: converting simple C code to Java

    Start by trying to understand what the C code is doing

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: converting simple C code to Java

    What is the type of the 'roomcode' variable?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    sbutt is offline Member
    Join Date
    Apr 2009
    Posts
    20
    Blog Entries
    1
    Rep Power
    0

    Default Re: converting simple C code to Java

    i think it is better to write a simple java program instead of decoding this C code. But thanks anyway.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: converting simple C code to Java

    Understanding the code is what is needed, mindlessly translating code is simple, with enough banging on the keyboard you will figure something out eventually. This process is simply time consuming. If you understand what the c code does, it will take very little time to write the equivalent java code.

Similar Threads

  1. Problem with simple code in Java ME SDK 3.0
    By marvas in forum CLDC and MIDP
    Replies: 0
    Last Post: 10-13-2010, 07:58 PM
  2. Simple Java BlueJ Converting Program
    By Mahoo in forum New To Java
    Replies: 3
    Last Post: 08-04-2010, 06:28 AM
  3. Converting simple Java Application to Applet
    By jrohde in forum Java Applets
    Replies: 1
    Last Post: 07-25-2009, 08:48 PM
  4. please help in java code (simple)
    By rahul_swe23 in forum New To Java
    Replies: 4
    Last Post: 01-26-2009, 04:32 PM
  5. problem with a simple java code
    By boy22 in forum New To Java
    Replies: 2
    Last Post: 08-03-2007, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •