Converting char to int

I am dealing with this problem.
I need to read a file through this code:
byte[] b;
File file = new File(path);
FileInputStream inFile = new FileInputStream(file);
inFile.read(b);
But then i dont know how to convert the byte into int types.
For istance i have that b[0] = "0", and i would like to get the number 0 instead of the char.
Then i have that b[1] = "1", b[2] = "2",b[3] = "3", and i would like to get the whole number 0123.
How can i do?
Thank you in advance
-- Andy

Firstly, you need to tell use what the format of the file is:
b[0] = "0" states that the first element in the byte array is a string containing a single 16bit character '0'.
Interger.parseInt(new String(b)); might work, but your description is not precise enough to say.
Pete

Similar Messages

  • Converting chars to ints, get a strange math error...

    Here's the code I have.
    import java.util.*;
    public class Encryption {
         public static void main(String[] args) {
              Scanner sc1 = new Scanner(System.in);
              System.out.print("Enter a four-digit integer to be encrypted: ");
              String encrypt = sc1.nextLine();
              char a = encrypt.charAt(0);
              char b = encrypt.charAt(1);
              char c = encrypt.charAt(2);
              char d = encrypt.charAt(3);
              int as = new Integer(a).intValue();
              int bs = new Integer(b).intValue();
              int cs = new Integer(c).intValue();
              int ds = new Integer(d).intValue();
              int codea = (as + 7);
              while (codea > 9) {codea = codea - 10;}
              int codeb = (bs + 7);
              while (codeb > 9) {codeb = codeb - 10;}
              int codec = (cs + 7);
              while (codec > 9) {codec = codec - 10;}
              int coded = (ds + 7);
              while (coded > 9) {coded = coded - 10;}
              int finala = codec;
              int finalb = coded;
              int finalc = codea;
              int finald = codeb;
              String encrypted = ("" + finala + "" + finalb + "" + finalc + "" + finald + "");
              //System.out.println ("The encrypted number is " + encrypted + ""); set aside while debugging
              System.out.println(" " + a + " " + b + " " + c + " " + d + " ");
              System.out.println(" " + as + " " + bs + " " + cs + " " + ds + " ");
    }Now here's the console.
    Enter a four-digit integer to be encrypted: 1234
    1 2 3 4
    49 50 51 52
    When I went from char to int, 1 became 49, 2 became 50, etc...how did this happen?

    class Fubar1
        public static void main(String[] args)
            System.out.println("'1' = " + '1'); // prints the char
            System.out.println("(int)'1' = " + (int)'1'); // prints the ASCII (unicode?) number that represents that char
    }

  • Convert char to int ?

    Character c = new Character(x.charAt(k));
                        String s = c.toString();
                        int i = Integer.parseInt(s);
    Is there an easier way to do it than this?

    Well, sort of int i = Integer.parseInt( Character.toString( x.charAt( k ) ) );andint i = (int)x.charAt( k ) - (int)'0'; // should use Character.isDigit( char c ) to ensure that k-th char is a digitandint i = Integer.parseInt( x.substring( k, k+1 ) ); // should use x.length() > k+1 to ensure that k+1 is a valid indexWhat do you want to do? Why don't you parse the whole String as inint i = Integer.parseInt( x );

  • Converting char to int - Easy surely?!

    A very easy question I know but it's drving me round the bend!!!
    I have searched the forums but the answers I have seen don't seem to work?!
    Basically I have a section of code like this:
    String argument = "-0";
    int member = (int)argument.charAt(1);
    member then gets populated with 48 and not 0. Why??!
    Any help would of course be greatly appreciated.

    48 is the internal representation of the character '0'. This is not only true for the Unicode used by Java but also for the ANSI and ASCII codes. The character coded as 0 is often used as string terminator, e.g. for the standard C strings.
    So if you want to retrieve the value of a digit character, you need to subtract 48. But make sure it is a digit, i.e. a character code between 48 and 57, both inclusive. You might also want to check out the method Integer.parseInt(String).

  • Fm for converting char3 to int

    suggest me a function module for converting char of length 3 to int
    and a function module for converting from int to char 3

    Hi ,
    You dont require a FM for that.
    Simply do the following:
    Data : l_temp(3) type c,  " CHar
              l_sum     type i.    " Integer
    * To move char to integer
    L_temp = '1234'.
    move l_temp to l_sum.
    * To move integer to char
    clear : l_temp, l_sum.
    l_sum = '23433'.
    move l_sum to l_temp.
    Best regards,
    Prashant

  • Converting char to decimal value format as defined in SU3(User profile)

    Hi Techies,
    Is there any FM to convert CHAR value into Decimal fomat as defined in SU3.
    If we use, WRITE statement for printing the value in decimal format , it shows the value in decimal format correctly
    in SU3 transaction , there are three different decimal format notations which can be user specific
    I would appreciate your valuable inputs ....
    Thanks
    Santhosh

    This is my code in a generic method to transform a table into a csvrow
    when 'P'.
            tmpstr = <p_field>.
            len = strlen( tmpstr ) - 1.
            tmpstr = tmpstr+0(len).
            if <p_field> < 0.
              sign = '-'.
            else.
              sign = ' '.
            endif.
            case decimalformat.
              when 'X' or 'E'.
                split tmpstr at '.' into int frac.
                ptmp = int.
                write ptmp to cp.
                shift cp left deleting leading space.
                replace all occurrences of '.' in cp with ','.
                concatenate
                  s
                  sign
                  cp
                  frac
                  delimiter
                into s in character mode.
              when 'Y' or 'D'.
                split tmpstr at '.' into int frac.
                ptmp = int.
                write ptmp to cp.
                shift cp left deleting leading space.
                replace all occurrences of ',' in cp with '.'.
                concatenate
                  s
                  sign
                  cp
                  frac
                  delimiter
                into s in character mode.
              when ' '.
                concatenate s sign tmpstr delimiter into s in character mode.
              when others.
                concatenate s '????????' delimiter into s in character mode.
            endcase.
    where pfield is a fieldsymbol type P. (honestly ist from type any, but determined by RTTI). I needed this cause i want to format the value from "outside" without taking the user settings in consideration as write...to.. is doing.
    What i'm doing is to use the write... to... clause modifying the result (change decimal point, thousand separator and sign) according to the demanded decimal notation.
    Edited by: Rainer Hübenthal on Oct 7, 2009 4:47 PM

  • How to convert char array to string

    sirs,
    i have written a method in java which will return a randomly generated string of a fixed length. i am creating one one character and inserting it into char array.
    at last i am converting it to string
    like this
    String newpass= pass.toString();// pass is a char array
    but problem is that the string is having different value what i hav generated.
    if i am doing like this..
    String newpass= new String(pass);// pass is a char array
    here newpass is having correct value but having some error
    error in the sense when i print
    System.out.println(newpass+"some text");
    "some text" is not printing
    can you suggest the better way

    /*this is my method */
    private String generateString(int len){
              char pass[] = new char[10];
              int cnt=0;
              int temp=0;
              Random randomGenerator = new Random();
                   for (int idx = 0; idx < 1000; ++idx)
                        temp = randomGenerator.nextInt(1000)%128;
                   if((temp>=65 && temp<=90)||(temp>=97 && temp<=122)||(temp>=48 && temp<=57))
                             pass[cnt]=(char)temp;
                             cnt++;               
                        if(cnt>=len) break;
                   String newpass= pass.toString();
                   String newpass1= new String(pass);
                   System.out.println("passed pass"+newpass+"as"+newpass1+"sa");
              return newpass;
    here newpass and newpass1 are having separate values
    why ??
    Edited by: Shovan on Jun 4, 2008 2:21 AM

  • Convert char to currency

    Hi all,
    i searched alot but couldn't find solution.
    i have l_value char(45) field value has 4560
    I need to convert this into vbak-netwr field in sales order user exit MV45AFZZ
    when i assign vbak-netwr = l_value.
    I am getting 45.60 in vbak-netwr field.
    when i try same login in report progam it is working fine but not in user exit.
    any suggestions?
    Giri

    Sample program to convert Char to Curr.
    data: curr type kna1-umsa1,
          char(254) type c.
    data: temp type p length 15 decimals 2.
    char = '1,405.25'.
    REPLACE ALL OCCURRENCES OF '.' IN char WITH space.
    REPLACE ALL OCCURRENCES OF ',' IN char WITH space.
    CONDENSE char NO-GAPS.
    temp = char.
    curr = temp / 100.
    write: 'CHAR = '.
    write :/ char.
    write:/ 'CURR = '.
    write: curr.
    << Removed by moderator >>
    Regards,
    Uttam Agrawal
    << Removed by moderator >>
    Edited by: uttamagrawal on Feb 22, 2011 9:21 AM
    Edited by: Neil Gardiner on Feb 22, 2011 9:01 PM

  • Convert Char to Date format - Evaluate

    Hi,
    Could anyone provide us the Evaluate formula to convert Char to Date format
    2009-06-20 should be converted to 06/20/2009
    Regards,
    Vinay

    Hi,
    Refer the below threads...
    Re: How to convert string to date format?
    how to convert character string into date format????
    Regards,
    Chithra Saravanan

  • Convert char to ascii code and vice versa

    HI
    Is there any function module to convert char to ascii code and vice versa.
    Thanks in advance

    Hi,
    be careful if you have unicode running in your system. URL_ASCII_CODE_GET is platform-dependent so it will return the internal HERX representation of the character in your system - which is hopefully and in most cases ASCII.
    Under unicode, we use double-byte characters here. I tried this function and the result CHAR_CODE is '00' regardless what character I specify for TRANS_CHAR. But the coding is so simple I corrected resultig in this sample code:
    [P]
    convert p_form to ASCII (internal) representation
      DATA:
        l_ofs TYPE syfdpos,
        l_len TYPE sy-linsz,
        l_ascii TYPE i.
      FIELD-SYMBOLS:
        <x> TYPE x.
      l_len = STRLEN( p_ascii ).
      DO l_len TIMES.
        l_ofs = sy-index - 1.
        ASSIGN p_ascii+l_ofs(1) TO <x> CASTING.
        l_ascii = <x>.
        WRITE: l_ascii.
      ENDDO.
    [/P]
    Here, for each character of string p_ascii, the internal (ASCII) representation is determined and written to the output list.
    Regards,
    Clemens

  • Convert Char to Date in SQL Server

    Hello Experts,
    I am trying to convert Char to Date but getting error in Universe designer. Can anybody advise please?
    Thanks,
    Ravi

    Hi,
    Try with CAST() and CONVERT() functions. For more information refer use this url : http://msdn.microsoft.com/en-us/library/ms187928.aspx.
    It is more easy to get solution if you can post your query.
    Cheers,
    Suresh Babu Aluri.

  • Convert char to dec

    Dear all ,
        I have to convert char to dec , my requirement is to covert  12344434 to 123444.34 .
    note i don't want 12344434 to 12344434.00 .
    Thanks in advance
    Debesh

    You can try like this.
    DATA : v_tot_len TYPE i,
            v_off_len TYPE i.
    DATA : v_off_text(50) TYPE c,
            v_dec_text(2)  TYPE c,
            v_fin_text(50) TYPE c.
    PARAMETERS : p_input TYPE text20 OBLIGATORY.
    START-OF-SELECTION.
    v_tot_len = STRLEN( p_input ).
    v_off_len = v_tot_len - 2.
    v_off_text = p_input+0(v_off_len).
    v_dec_text = p_input+v_off_len(2).
    CONCATENATE v_off_text v_dec_text INTO v_fin_text SEPARATED BY '.'.
    Here I am inputting the text to be converted.

  • Convert char * to LPCTSTR

    How I can convert char * to LPCTSTR.
    I reading msdn but I don't know nothing sensible to do.
    Thx for all hepl.

    If your program is not using Unicode as the default, then "char *" is the same thing as LPCTSTR; the compiler will see the same thing, the only difference is that the preprocessor replaces LPCTSTR with "char *".
    Your program however is probably using Unicode as the default. If so, then you need to convert the non-Unicode "char *" string to a Unicode string. There are many ways to do that and the most convenient solution for you depends on what your program is already using. If your program is using MFC then there is a MFC solution. If your program is using the CLI (.Net) then there is a different solution using that. If your program uses the C++ standard classes (std namespace) then there is a solution using that. There is also a solution using the C runtime and anotehr using the Windows SDK.

  • Function modules for converting Char value to hexadecimal value

    Hi All,
    Function modules for converting Char value to hexadecimal value.
    Thanks in advance

    Hi,
    use this function module:
    <b>RSS_UNIQUE_CONVERT_TO_HEX</b>
    regards
    Debjani
    Rewards point for helpful answer

  • Converting CHAR or CLOB to BLOB in Oracle9i

    Hi!
    I want to convert CHAR or CLOB to BLOB.
    I am working with Oracle9i Database.
    Oracle9i Supplied PL/SQL Package Release 2 (9.2) does'nt support DBMS_LOB.CONVERTTOBLOB procedure.
    How I can convert CHAR or CLOB to BLOB in Oracle9i?
    Valery

    Hi Valery,
    For conversion to blob, just try the utl_raw package.
    I use utl_raw.cast_to_raw quite often.
    Or have a look at:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:437819871174
    Good luck,
    Jan-Marcel

Maybe you are looking for

  • Custom Application in CRM 5.0 SP13

    We have made changes as per note 1017761 to get a custom application working ... In the attached file I have made a summary of the errors related to the "sap.com/home~syn_crm" application. Overall we have 3 missing references to classes or classes de

  • How can I start up my ipod 120GB classic without a firewire connection? Is this possible to do?

    I have had this ipod for 2 years and its been sitting in a box because I didnt know how to fix it, thought I'd give it a whirl tonight. It stopped working, displaying the red X screen and Im trying reboot/reset it and  I am at the Accessorize Test. H

  • SSH / Expired Passwords

    I've recently installed a batch of servers with Solaris 10 10/08 and have noticed that the way the Solaris sshd implementation deals with password change on login is different to previous versions of Solaris SSH and/or OpenSSH installed in out enviro

  • What Router Would Be Best If Using Two PlayStation 3 Consoles?

    What Router Would Be Best If Using Two PlayStation 3 Consoles That  Are Connected To The Same Broadband Internet Connection? My Two Cousins Aren't Able To Connect To The Same Lobby Party Together As I Am To Play COD MW3. They Have Tried Having Both C

  • Creating DB Control

    Hi, I try to create DB control grid like following : C:\oracle\product\10.2.0\db_1\BIN>emca.bat -config dbcontrol db STARTED EMCA at Nov 18, 2008 7:14:05 AM EM Configuration Assistant, Version 10.2.0.1.0 Production Copyright (c) 2003, 2005, Oracle.