Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Baby Lion - 02 Oct 2006 02:43 GMT
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[i] = b[i];
        }
        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 - 02 Oct 2006 02:44 GMT
// 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
[quoted text clipped - 47 lines]
>     }
> }
Baby Lion - 02 Oct 2006 02:45 GMT
// 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;
    }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.