Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 10th, 2003, 04:45 AM
phani phani is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 phani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation on java

i need help from u. Write code for the following two methods. Read them u can understand. First one is converting int array to byte array
the thing i written is wrong. u test them and then send code.


/**
* Converts an integer array into a byte array.
*
* @param integers the integer array
* @return the converted byte array
*/

// FIX: Each integer has 4 bytes. each integer must be split
// and each byte assigned to a separate array element.
// therefore the number of bytes returned will be 4 times
// the length of the input array.

// FIX: shift and mask the integer to get each byte.
/*


public static byte [] convertIntegersToBytes (int [] integers) {

if ( integers !=null ) {
int len_of_integers = integers.length;
byte outputBytes[] = new byte[len_of_integers * 4];

int cur_idx_of_outputBytes = 0;

for(int idx=0; idx < len_of_integers; idx++) {
int integerTemp = integers[idx];
for(int inner_idx=0; inner_idx < 4; inner_idx++) {
outputBytes[cur_idx_of_outputBytes] = ( (integerTemp >> (8*inner_idx) ) & 0xFF );
cur_idx_of_outputBytes++;
}
}
return outputBytes;
} else {
return null;
}

}




/**
* Converts a byte array into an integer array.
*
* @param inputBytes the byte array
* @return the converted integer array
*/
public static int [] convertBytesToIntegers (byte [] inputBytes) {

// FIX: same issue as with the above method.

if ( inputBytes != null ) {
int len_of_inputBytes = inputBytes.length;
int outputIntegers[] = new int[len_of_inputBytes];
for(int idx=0; idx < len_of_inputBytes; idx++) {
outputIntegers[idx] = inputBytes[idx];
}
return outputIntegers;
} else {
return null;
}
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > on java


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap