Char to int

Hi,
I have a received a datagram storing address IP in a byte[].
how can I write it on readable format.
thanks

In Java, byte is a primitive type that holds values in the range of -128 to 127. If you receive a byte array then the data is already in readable format.
If you mean someting else, then providing more details and not expecting us to mind read would be appreciated.

Similar Messages

  • Question about public void characters(char []ch, int start, int length) thr

    Can anyone tell me how you would keep all the characters from within one pair of tags together each time characters() is called?
    the character() method doesn't read all the character data at once, and i would like to create a buffer of what it has read.
    thank you.

    I recommend using getNodeName and/or/combination
    with
    getNodeValue to get the strings.i have tried using a buffer, and i have got that to work!
    At long last I am seeing the string I would like to see as it is in the xml file!
    thank you for your help
    here is an example of my code:
    private boolean isDescription = false;
    StringBuffer sb = new StringBuffer();
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
         if(localName.equals("description")) {
              sb = new StringBuffer();
              isDescription = true;
    public void characters(char []ch, int start, int length) throws SAXException {
         if(isDescription == true) {
              String desc = new String(ch, start, length);
              sb.append(desc);
    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
         if(localName.equals("description")) {
              isDescription == false;
              System.out.println(sb.toString());
    }

  • How to user bufferedreader.read(char[] cbuf,int off,int len)

    how to user bufferedreader.read(char[] cbuf,int off,int len)?
    can you give me an sample code? i dont understand the use of offset here... thanks!

    The offset simply gives you the ability to read in data starting at some point in the buffer other than the first character.
    If, for example, you are reading from some stream that is being filled slower than you are reading, then you can write a read loop that will fill the buffer with successive reads - the first at character 0, then next offset past the end of the first set of data, etc.

  • 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
    }

  • Int to char - char to int

    I have 2 methods.
    The first method takes an int from 0-256 and casts it to a char and then places the char in a string:
    cCryptedString [iLoop] = (char) iCryptedValue;
    The second method reads the string and casts each character from it into an int.
    iPassStringValue = (int) aString.charAt(iLoop);
    If the iCryptedValue in the 1st method is > 127 and < 150 (because that's as far as they will go at the moment), the casting of that int (i.e. 145) to a char results in a ? being placed in cCryptedString[iLoop].
    When the 2nd method reads the string and encounters the ? placed by the first method, the casting of that char to an int results in a 63 (the ascii value of a ?) instead of the original 145.
    This was not a problem until I installed and ran WebLogic 6.0 sp2 using jdk 1.3 on a Windows 2000 machine. It is working fine under WebLogic 5.1 using jdk 1.2.2.
    Any ideas?
    Thanks,
    Mark

    Here is the 1st method:
    public String encryptString(String aString) {
    int iPassStringValue = 0;
    int iEncryptKeyValue = 0;
    int iCryptedValue = 0;
    char cCryptedString [] = new char[aString.length()];
    for (int iLoop = 0; iLoop < aString.length(); iLoop++) {
    iPassStringValue = (int) aString.charAt(iLoop);
    iEncryptKeyValue = (int) sEncryptKey.charAt(iLoop);
    iCryptedValue = iPassStringValue + iEncryptKeyValue;
    if (iCryptedValue > 255)
    iCryptedValue = iCryptedValue - 256;
    cCryptedString [iLoop] = (char) iCryptedValue;
    return new String(cCryptedString);
    Here is the 2nd method:
    public String decryptString(String aString) {
    int iPassStringValue = 0;
    int iEncryptKeyValue = 0;
    int iDecryptedValue = 0;
    char cDecryptedString [] = new char[aString.length()];
    for (int iLoop = 0; iLoop < aString.length(); iLoop++) {
    iPassStringValue = (int) aString.charAt(iLoop);
    iEncryptKeyValue = (int) sEncryptKey.charAt(iLoop);
    iDecryptedValue = iPassStringValue - iEncryptKeyValue;
    if (iDecryptedValue < 0)
    iDecryptedValue = iDecryptedValue + 256;
    cDecryptedString [iLoop] = (char) iDecryptedValue;
    return new String(cDecryptedString);
    Thanks!!

  • 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

  • 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 );

  • Convert from char to int

    hey
    I've an input string ("1234")
    What i need to do is to fill a matrix 2*2 with the input string.
    I thought about running over the string, and by str.charAt(ind) to get a needed charters, but the question is ho do i convert charAt result to int?
    tanx

    igalep132 wrote:
    hey
    I've an input string ("1234")
    What i need to do is to fill a matrix 2*2 with the input string.
    I thought about running over the string, and by str.charAt(ind) to get a needed charters, but the question is ho do i convert charAt result to int?
    tanxThat's kinda vague. Do you mean convert '1' into the integer value 1 or convert '1' into the ASCII integer value of 49?
    Here's how to do the first:
    String one = "8";
    String two = "3";
    String numbers = "0123456789";
    int oneInt = numbers.indexOf(one);
    int twoInt = numbers.indexOf(two);
    System.out.println("oneInt = " + oneInt);
    System.out.println("twoInt = " + twoInt);If you meant the latter then ...
    char c = 'c';
    int cInt = (int)c;

  • Turning chars into ints

    i have a string which should be made up of just digits, and i want to take individual characters(digits) from that string and use them as ints. any ideas how to do this?
    when i try something like this:
    Integer.valueOf(baseRule.getText().charAt(i).asString()).intValue()
    it tells me i can't dereference a char...

    i haven't tried it but won't char c = 'c';
    int i = Integer.parseInt( c ); work?Has everybody forgotten C?:
    char c = . . .;
    int i = c - '0'; //for safety, do range checking!

  • Interprete char as int

    Hey,
    I created an array like the following:
    $Nums = @('1','2','3','4','5','6','7','8','9')
    I know this is an array of chars. That's what I want because I do some more stuff with this array.
    (I could do $Nums = 1..9, I know - but that is not what I want because I need the char first)
    In one point of my script I need to have this 'char' interpreted as int (e.g. $Nums[2] -> 3; NOT $Nums[2] ->
    '3').
    By casting ([int]$Nums[2] -> 51) unfortunately powershell changes the char to its ASCII value :(
    How can I make powershell interprete the char as the int that is behind the char?
    Thank you for help

    This was probably what was intended
    $Nums = @([char]'1',[char]'2',[char]'3',[char]'4',[char]'5',[char]'6',[char]'7',[char]'8',[char]'9')
    [char[]]$Nums = '1','2','3','4','5','6','7','8','9'
    [char[]][string[]]$Nums = 1..9

  • InputStreamRead read(char[] cbuf, int offset, int length) method hangs

    This method hangs for the following values
    read(xchar, 0, 1)
    Does not throw any exception.
    The inputstream does have data in it.
    the characterset is cp037.

    So the problem is probably in your implementation of InputStream. Do you implement the available() method? What will your class do if you attempt to read more bytes than there are? (say, call read(chars, 0, 1000000))
    The InputStreamReader keeps an internal buffer (of 1024 bytes?) which it uses for decoding the bytesto characters..if your stream blocks when InputStreamReader is filling its buffer you'd get this sort of behaviour.

  • Fact columns Datatype is changing from char to int in OBIEE 11g

    Hi ,
    I am taking measure columns - "product description","tot cost" against a dimension "project name" .
    I am generating this report in a planing form and OBIEE .
    in planing form :
    product description tot cost
    project name
    P1 A 1500
    p2 B 1700
    p3 C 1800
    in obiee report :
    product description
    project name
    P1 16 1500
    p2 17 1700
    p3 19 1800
    Somehow , measure's datatype are getting changed from char to number , in OBIEE report.
    By default , the data type for all fact's is Double .I tried changing that to varchar , but result is same .
    Do I need to change anything in physical layer / RPD .
    OBIEE version : 11.1.1.6
    Essbase version : 11.1.2

    Hi ,
    Thanks for your reply . To confirm , the data type of product description column is "double" in essbase .
    I found out ,thers's a RDBMS table , consisting of two columns - ID, text value . where product description's are in text value's with the corresponding ID's(integer values) .
    Now , when I am creating a form in planning , its fetching the text values of product description (there's some inbulit setting's available for this in plannng) .
    However , in obiee its fetching the ID values of product description .
    So ,
    1. Is there any similer setting I can do for OBIEE , so that it's fetches only text value's of product description .
    2. If not , then I have to join the essbase fact table with this RDBMS table . I am not sure how to do it .

  • 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).

  • How to convert an internal table of char type to Raw (1022 char) format int

    Hi All,
    I am facing the problem while converting the character type internal table to Raw (1022 char) format internal table.
    Example :
    Source :
    Internal table - Itab_send of type char132.
    Target : ( Required )
    Internal table - itab_receive of type SDOK_SDATX .
    Note : SDOK_SDATX = Raw ( 1022 char )
    Thank  you,
    Purshoth

    Possible Solution : Move it to source character field to string and string to raw field.
    try to find FM , go in se37 and *RAW *
    RSAB_CONVERT_RAW_TO_CHAR convert raw to char.
    Edited by: Harsh Bhalla on Dec 15, 2009 10:31 PM

  • Getting character by number, char of (int)

    I would like to create column header in the excel style for my app, eg AA, AB, AC....BA, BB...etc
    Is there a way to get the character by index in Java, so i can iterate the letters in a cycle,
    Something like charOf equivalent in java?
    Dennis

    I would like to create column header in the excel
    style for my app, eg AA, AB, AC....BA, BB...etc
    Is there a way to get the character by index in Java,
    so i can iterate the letters in a cycle,
    Something like charOf equivalent in java?
    DennisJust use cast: ((char)65) == 'A'), ((char)66) == 'B'), etc.

  • InputStreamReader read(char[] cbuf, int offset, int length) method hangs

    Hi all,
    I am posting this message again.
    I would appreciate any help, as I am stuck with a customer issue.
    This method hangs for the following values
    read(xchar, 0, 1)
    Does not throw any exception.
    The inputstream does have data in it.
    the characterset is cp037.
    I know for sure that the InputStream has data in it. In fact the read method reads couple of fields with length greater than 1 and hangs when it tries to read data with length 1.
    Bug # 4401798 talks about some error similar to this being fixed. Any one has any idea, which jdk had this problem and which one has a fix for this?
    Thanks.

    You should have continued in your original thread, rather than starting a new one. What you have posted in this new thread could have gone in the old one:
    http://forum.java.sun.com/thread.jspa?threadID=665303

Maybe you are looking for

  • Can't install Bootcamp, stuck in Windows XP

    Hey everybody, I recently got a MacBook Pro with OS X Lion. I partitioned the hard drive and successfully installed Windows XP. I tried to install Bootcamp, but I get an error message saying that Bootcamp can only be installed in Windows 7. How can I

  • ABC analysis & LIFO / FIFO evaluation

    Hi friends I am working in an implementation project 1. My client requirs to carry out ABC analysis. Does it need any configuration ...... Please tell me how to carry out ABC analysis.I also want to show them on SAND BOX & Development server ... What

  • Unable to start the CMS.

    Hi, We shutdown the  Business objects server and we started it after 2 days. when we are trying to start the CMS using ccm.sh -start all and using ccm.sh -enable all its not starting the server. when we went through the log file: Mon Jun 22 2009 11:0

  • With out try and catch

    with out any try and catch is exception handling is possible in java when doing manupulation with database. assume mydatabase is oracle,if i am going to insert a record of a primarykey field, which is already existing.i don't want to put with in try

  • I downloaded firefox 4 but want to go back to the one before 4, how do I do this?

    My Norton toolbar will not work with Firefox 4 and until they update the Norton tool bar I need to go back to the old version of Firefox. How do I do that?!?!