×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    8

    How to get a string from a sequence of bytes

    Hello,
    I would like some advice from you, my problem is I have a file maybe like:

    73 119 99 115 ... (a sequence of bytes)

    So, I can read the lines into a string, and from there I get the Integers and put them into a vector or something.

    I would like to know how can I get the string of that sequence. I tried with this:

    mybyte[0]=(byte)((num & 0xff000000)>>>24);
    mybyte[1]=(byte)((num & 0x00ff0000)>>>16);
    mybyte[2]=(byte)((num & 0x0000ff00)>>>8);
    mybyte[3]=(byte)((num & 0x000000ff));
    String r = new String(mybyte,"UTF-32");

    mybyte is an array of bytes, and num would be each integer, but I do not get the string correctly at all.
    Last edited by Alvarodt; 2010-12-20 at 12:03.

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to get a string from a sequence of bytes

    Maybe you should ask your instructor, or one of your classmates. In any event, it's hard for us to guess what the "specified technique" is.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    8

    Re: How to get a string from a sequence of bytes

    This is the answer but I still dont get it. -> (char)num
    Last edited by Alvarodt; 2010-12-20 at 12:04.

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to get a string from a sequence of bytes

    Well, first, if you're supposed to read the numbers as "byte" you should probably use a byte-reading operation such as DataInputStream.readByte or readFully.

    But maybe you should pay more attention in class?

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    8

    Re: How to get a string from a sequence of bytes

    This is another thing. And you don't read "bytes", you read a number in a string like '73', and that's 'the byte'.

Similar Threads

  1. Replies: 2
    Last Post: 2010-09-03, 21:12
  2. Get bytes of a String in Symbian
    By jobin.tech in forum Symbian
    Replies: 4
    Last Post: 2008-12-15, 09:46
  3. SOS:accept bytes of a jpg file from the J2EE,but losing some bytes.
    By jerrysdfha in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2007-01-31, 01:39
  4. Convert bytes in String
    By decisor in forum Mobile Java General
    Replies: 8
    Last Post: 2006-08-03, 18:56
  5. Replies: 5
    Last Post: 2006-02-26, 17:29

Posting Permissions

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