How to Convert Integer to byte[n]!Help

I have a Integer 314,Convert to hex is 0x13a,I want to convert to byte[2],and byte[0] equals 0x13 and byte[1] equals [0x30];I use this method convert byte[4],
int iVal = 314;
byte [] bVals = new byte[4];for( int i=0; i<4; i++ ) { 
bVals<i> = (byte)(iVal & 255);
iVal >>= 8;
Not I want to result.Please help!

Try:
int iVal = 0x01FF03F0;
byte [] bVals = new byte[4];
for(int i=3; i>=0; i--) {
    bVals[i] = (byte)(iVal & 255);
    iVal >>= 8
//print results
for (int i = 0; i < 4; i++) {
   int temp = bVals[i] & 0xFF;  // avoid displaying negative numbers
   System.out.println("byte " + i + " = " +  Integer.toHexString(temp));
}

Similar Messages

  • How to convert integer to string?

    for example :
    int num = 1;
    String num_str;
    how to convert the value of num variable to string .

    have u ever checked the documentation of WTK
    one method called valueOf
    will help u
    alpesh

  • How to convert video files on itunes help

    how do you convert a movie file using itunes?
    i have a movie file randomly as .mkv
    thanks!

    Well I suggest that you check out the other pages on that site - you might get some info on how to convert - or - do a Google search for a converter program.
    In some respects your question is not about iTunes but about how to convert a file into a format that iTunes/QT can play. QT plays various CODECS and there are a number of plugins available for QT to play additional CODECS beyond the standard default set.
    MJ

  • How to change integer to byte value

    i need to change long/integer/short number to byte value , on the other hand, convert byte value to long/integer/short.
    is there anyone can tell me how to do it?

    OK I'll byte no real pun intended though.
    I am having all kinds of trouble outputing to a stream.
    I have a value that is an integer 47012 and I
    cast it
    int foo = 47152
    byte bar = (byte) foo;
    System.out.println(foo); //just to see if the int is ok
    // I am seeing 47152
    System.out.println(bar); // in a crazed attempt to get a check of the value
    // I am seeing 48
    oStream.write(bar);
    the file I am writing to is filled instead with
    all 30. I know that 30 = 48 in hex so this makes some sense as java is converting the byte to dec 48.
    what I dont get is that 47152 = B830 so since I am to collect my data and then convert it to a byte and since I am loosing the top 2 digits how to I preserve them to output to the stream?

  • How to convert 750 to byte

    I have a integer 750,I want to convert to bytes,and arrange to byte[8],--byte[11]
    value is EE 02 00 00??
    How to ???

    Here's one way.          int v = 750;
              byte[] b = new byte[12];
              for(int i=8;i<12;i++) {
                   b[i] = (byte) (v & 255);
                   v >>>= 8;
              for(int i=8;i<12;i++) {
                   System.out.println(Integer.toHexString(b[i] & 255));

  • How to convert flv into mp3 -- please help!

    hi,
    i'm very new to using videos in flash. i uploaded a video into flash in order to add texts to it to upload later to web. my problem is converting the fla file to mp3. i tried the video encoder but i'm stuck. please help if you can..it'll be very much appreciated. thanks!

    i think i see where the problem lies. the file i worked on in flash (i inserted some texts into the video) are saving as .fla. how do i get it to change to flv in order to use the service you suggested? thanks a bunch!

  • How to convert integer to object?

    i want to use a Object array to store two integer variable
    how can i do that?

    Object[] my_array=new Object[2];
    Integer int1=new Integer(7);
    Integer int2=new Integer(42);
    my_array[0]=int1;
    my_array[1]=int2;- Marcus

  • Premiere elements 2.0    how to convert mpeg to avi   PLEASE HELP

    Here is my problem, I am putting together a hi light video for my sons football seasons. Most of the seasons I have videotaped myself. When I capture the video in Elements it creates several avi files that I can pick and choose from, each file is created from when I pause during recording. I have one seasons worth of videos where I was not the one taping. I have dvd discs that the guy taping gave me. I can put the dvd file into elements and even put it in the time line but it shows up as one long clip....not segmented. It is also an mpeg file. I can use the razor tool to segment it in spots but have no way to convert the file within elements. When I save the project it still stays as one continuous mpeg file in my adobe folder regardless of whether or not I segment it with the razor tool. Oh, and if I haven't made it clear yet I am an Elements idiot. How can I get the files off the dvd to use in the manner in which I need to use them????? Do I have to use a seperate program to make them avi files?????

    <[email protected]> wrote in message<br />news:[email protected]<br />> Here is my problem, I am putting together a hi light<br />> video for my sons football seasons. Most of the seasons I<br />> have videotaped myself. When I capture the video in<br />> Elements it creates several avi files that I can pick and<br />> choose from, each file is created from when I pause<br />> during recording. I have one seasons worth of videos<br />> where I was not the one taping. I have dvd discs that the<br />> guy taping gave me. I can put the dvd file into elements<br />> and even put it in the time line but it shows up as one<br />> long clip....not segmented. It is also an mpeg file. I<br />> can use the razor tool to segment it in spots but have no<br />> way to convert the file within elements. When I save the<br />> project it still stays as one continuous mpeg file in my<br />> adobe folder regardless of whether or not I segment it<br />> with the razor tool. Oh, and if I haven't made it clear<br />> yet I am an Elements idiot. How can I get the files off<br />> the dvd to use in the manner in which I need to use<br />> them????? Do I have to use a seperate program to make<br />> them avi files?????<br /><br />If you want to subdivide a file on the timeline in APE 2:<br /><br />(1) Move the Work Area markers on the timeline to include just the portion <br />you wish to export as a separate file.<br /><br />(2) Go to File, Export, Movie<br /><br />(3) In the Settings Window of the Movie Export dialog select:   Range, "Work <br />Area Bar"<br /><br />(4) Save the file with the desired name.<br /><br />Repeat as desired to create separate segment video files for each segment <br />you wish to work with separately.<br /><br />When you are all done creating the segment video files, start a new project <br />and assemble the files as desired.

  • SSRS Convert Integer to Date

    Does anyone know how to convert integer to date in SSRS Report?
    The integer is in this format: 20140404
    Thank you.

    Is it a parameter?
    Is it a report result set?? Please post complete details.
    With less info I assume that is not a interger, It is just a different date format. See below
    Date Patterns
    if it is a real integer, sample
    Declare @test int=20140404
    SELECT cast (convert (varchar(8),@test) as date)
    - please mark correct answers

  • How to convert an Integer to byte[] without lose data?

    How to convert an Integer to byte[] without lose data?

    I use the following to convert any java Object to a byte array
    public static byte[] getBytes(Object obj) throws java.io.IOException
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            oos.flush();
            oos.close();
            bos.close();
            byte [] data = bos.toByteArray();
            return data;
    }

  • How to convert byte into string

    can any tell me how to convert byte into string
    when im an debugging thid code in eclipse it shows the result in integer format instead of string but in command prompt it is showing result in string format..........plz help
    package str;
    import java.io.*;
    public class Testfile {
    public static void main(String rags[])
    byte b[]=new byte[100];
    try{
    FileInputStream file=new FileInputStream("abc.txt");
    file.read(b,0,50);
    catch(Exception e)
         System.out.println("Exception is:"+e);
    System.out.println(b);
    String str=new String(b);
    System.out.println(str);
    }

    Namrata.Kakkar wrote:
    errors: count cannot be resolved and Unhandled exception type Unsupported Encoding Exception.
    If i write an integer value instead of "count" then Unhandled exception type Unsupported Encoding Exception error is left.This is elementary. You need to go back to [http://java.sun.com/docs/books/tutorial/|http://java.sun.com/docs/books/tutorial/] .

  • How can i convert object to byte array very*100 fast?

    i need to transfer a object by datagram packet in embeded system.
    i make a code fallowing sequence.
    1) convert object to byte array ( i append object attribute to byte[] sequencailly )
    2) send the byte array by datagram packet ( by JNI )
    but, it's not satisfied my requirement.
    it must be finished in 1ms.
    but, converting is spending 2ms.
    network speed is not bottleneck. ( transfer time is 0.3ms and packet size is 4096 bytes )
    Using ObjectOutputStream is very slow, so i'm using this way.
    is there antoher way? or how can i improve?
    Edited by: JongpilKim on May 17, 2009 10:48 PM
    Edited by: JongpilKim on May 17, 2009 10:51 PM
    Edited by: JongpilKim on May 17, 2009 10:53 PM

    thanks a lot for your reply.
    now, i use udp socket for communication, but, i must use hardware pci communication later.
    so, i wrap the communication logic to use jni.
    for convert a object to byte array,
    i used ObjectInputStream before, but it was so slow.
    so, i change the implementation to use byte array directly, like ByteBuffer.
    ex)
    public class ByteArrayHelper {
    private byte[] buf = new byte[1024];
    int idx = 0;
    public void putInt(int val){
    buf[idx++] = (byte)(val & 0xff);
    buf[idx++] = (byte)((val>>8) & 0xff);
    buf[idx++] = (byte)((val>>16) & 0xff);
    buf[idx++] = (byte)((val>>24) & 0xff);
    public void putDouble(double val){ .... }
    public void putFloat(float val){ ... }
    public byte[] toByteArray(){ return this.buf; }
    public class PacketData {
    priavte int a;
    private int b;
    public byte[] getByteArray(){
    ByteArrayHelper helper = new ByteArrayHelper();
    helper.putInt(a);
    helper.putInt(b);
    return helper.toByteArray();
    but, it's not enough.
    is there another way to send a object data?
    in java language, i can't access memory directly.
    in c language, if i use struct, i can send struct data to copy memory by socket and it's very fast.
    Edited by: JongpilKim on May 18, 2009 5:26 PM

  • How to convert bytes[] into File object

    hi
    how to convert byte array into File object
    pls.. help me
    Regards
    srinu

    rrrr007 wrote:
    Hi,
    How to convert bytes[] into multipage File object?? ]There's no such thing as a "multipage File object." You ought to re-read this thread closely, and read the [API docs for File|http://java.sun.com/javase/6/docs/api/java/io/File.html] to clear up your confusion about what a File object is.
    I used the java.io.SequenceInputStream to concatenate two input streams (basically .pdf files) into a single input stream. I need to create a single multipage pdf file using this input stream. Then you need a pdf API, like iText or fop. You can't just concatenate pdf files, word docs, excel sheets, etc., like you can text files. Google for java pdf api.

  • How to convert bytes[] into multipage File object

    Hi,
    How to convert bytes[] into multipage File object??
    I used the java.io.SequenceInputStream to concatenate two input streams (basically .pdf files) into a single input stream. I need to create a single multipage pdf file using this input stream.
    Thanks for you help in advance..

    Only text format allows you to concatenate two files together to get a longer files.
    Most formats have a header and a footer and so you cannot simply add one to the other.
    You need to use a PDF API which will allow you to build the new document (if one exists)

  • How to convert a Image object to byte Array?

    Who can tell me, how to convert Image object to byte Array?
    Example:
    public byte[] convertImage(Image img) {
    byte[] b = new byte...........
    return b;

    Hello,
    any way would suit me, I just need a way to convert Image or BufferedImage to a byte[], so that I can save them. Actually I need to save both jpg and gif files without using any 3rd party classes. Please help me out.
    thanx and best wishes

Maybe you are looking for

  • Why do we use super when there is no superclass?

    Hello, I have a question about the word "super " and the constructor. I have read about super and the constructor but there is somethong that I do not understand. In the example that I am studying there is a constructor calles " public MultiListener(

  • Problems reporting work completition in a evaluation

    Hi Experts, I am trying to extract in an <b>evaluation</b> the <b>percentage of work completed</b> in a task. I found an attribute called <b>WORK_COMPLETE</b> but is not showing any results over a project that has this field filled out (in the evalua

  • Regarading IDOC status 26 ,syntax error

    Hi All, we have some problem to create IDOC type ORDERS05 for Purchase Order. *ERROR STATUS 26:* (SYNTAX ERROR IN IDOC (SEGMENT CANT B IDENTIFIED)) msg number E0078: The segment E1EDK14 does not occur at the current level of the basic type ORDERS05 (

  • BAPI Web Service

    Hi, I need to create a web dynpro component that will use a SAP provided webservice (e.g. BAPI_PERSDATA_GETDETAILEDLIST) and display the results. Now the access to the webservice WSDL provided by the R/3 server requires authentication. So when I trie

  • Another Safari Crash thread....

    Happens consistently now, after about fifteen seconds-will open home page, then crashes. Have tried the Quicktime plist fix, the history plist fix, the reset, emptied the cache, tried different accounts. Here's the report: Date/Time: 2007-08-17 00:31