|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
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; } } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > on java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|