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

B

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 ;
}
}
}
 
B

Baby Lion

// 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 写é“:
 
B

Baby Lion

// 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;
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top