is there a good way to change between int array and byte array ?

Discussion in 'Java' started by Baby Lion, Oct 2, 2006.

  1. Baby Lion

    Baby Lion Guest

    Hi,Everyone:
    Here is my solotion to change from int to byte[] ,is there a better
    solution ?

    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import javax.sql.rowset.serial.*;
    public class Indexes {

    public int hashCode;
    public String hashString;
    public SerialBlob blob;
    public byte[] b;
    public int length;
    public int numberOfIDs;
    public int capability;
    public ArrayList intArray;
    public int lastid; // to make note of last insert ID of intArray
    public void DoubleSize()
    {
    byte temp[] = new byte[capability*2];
    for(int i = 0 ; i< length; i++)
    {
    temp = b;
    }
    b = temp;
    }
    public void AddToBytes(int x)
    {
    int temp = x;
    for( int i = 0 ;i<=3 ; i++ ){
    b[length++] = new Integer(x & 0xFF).byteValue();
    temp = temp >> 8;
    }

    }
    public void IntToByte ()
    {
    b = new byte [intArray.size()*5+20];
    length = 0;
    this.capability = intArray.size()*5+20;
    for(int i = 0 ;i<intArray.size() ;i++)
    {
    if (this.capability -5 < length ) { DoubleSize();}
    Index temp = (Index)intArray.get(i);
    AddToBytes(temp.fileid);
    b[length++] = temp.pos ;
    }
    }
    }
     
    Baby Lion, Oct 2, 2006
    #1
    1. Advertising

  2. Baby Lion

    Baby Lion Guest

    // Index.java
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import javax.sql.rowset.serial.*;
    public class Index {

    public int fileid;
    public byte pos;
    public Index(int id, byte pos)
    {
    this.fileid = id;
    this.pos = pos;
    }
    }

    Baby Lion 写é“:

    > Hi,Everyone:
    > Here is my solotion to change from int to byte[] ,is there a better
    > solution ?
    >
    > import java.util.*;
    > import java.io.*;
    > import java.lang.*;
    > import javax.sql.rowset.serial.*;
    > public class Indexes {
    >
    > public int hashCode;
    > public String hashString;
    > public SerialBlob blob;
    > public byte[] b;
    > public int length;
    > public int numberOfIDs;
    > public int capability;
    > public ArrayList intArray;
    > public int lastid; // to make note of last insert ID of intArray
    > public void DoubleSize()
    > {
    > byte temp[] = new byte[capability*2];
    > for(int i = 0 ; i< length; i++)
    > {
    > temp = b;
    > }
    > b = temp;
    > }
    > public void AddToBytes(int x)
    > {
    > int temp = x;
    > for( int i = 0 ;i<=3 ; i++ ){
    > b[length++] = new Integer(x & 0xFF).byteValue();
    > temp = temp >> 8;
    > }
    >
    > }
    > public void IntToByte ()
    > {
    > b = new byte [intArray.size()*5+20];
    > length = 0;
    > this.capability = intArray.size()*5+20;
    > for(int i = 0 ;i<intArray.size() ;i++)
    > {
    > if (this.capability -5 < length ) { DoubleSize();}
    > Index temp = (Index)intArray.get(i);
    > AddToBytes(temp.fileid);
    > b[length++] = temp.pos ;
    > }
    > }
    > }
     
    Baby Lion, Oct 2, 2006
    #2
    1. Advertising

  3. Baby Lion

    Baby Lion Guest

    // Index.java
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import javax.sql.rowset.serial.*;
    public class Index {

    public int fileid;
    public byte pos;
    public Index(int id, byte pos)
    {
    this.fileid = id;
    this.pos = pos;
    }
    }
     
    Baby Lion, Oct 2, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,237
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,686
    Old Wolf
    Jan 20, 2004
  3. arun
    Replies:
    8
    Views:
    468
    Dave Thompson
    Jul 31, 2006
  4. Lew

    Re: byte + byte -> int

    Lew, Mar 20, 2009, in forum: Java
    Replies:
    6
    Views:
    389
    Arne Vajhøj
    Mar 21, 2009
  5. Alain Spineux
    Replies:
    6
    Views:
    644
    Eric Sosman
    May 17, 2011
Loading...

Share This Page