Java Array Swap swap(int array[], int first, int last)

Here you can find the source of swap(int array[], int first, int last)

Description

swap the bytes of an integer array

License

Open Source License

Parameter

Parameter Description
array array of integers to be flipped
first starting element of the array
last last element of array to flip

Declaration


public static void swap(int array[], int first, int last)

    

Method Source Code

//package com.java2s;
/*/*w  ww.ja v a 2 s. c  o  m*/
This source file is part of the edu.wisc.ssec.mcidas package and is
Copyright (C) 1998 - 2011 by Tom Whittaker, Tommy Jasmin, Tom Rink,
Don Murray, James Kelly, Bill Hibbard, Dave Glowacki, Curtis Rueden
and others.
     
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
    
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.
    
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/

public class Main {
    /**
     * swap the bytes of an integer array
     *
     * @param array    array of integers to be flipped
     * @param first    starting element of the array
     * @param last    last element of array to flip
     *
     */

    public static void swap(int array[], int first, int last)

    {
        int i, k;
        for (i = first; i <= last; i++) {
            k = array[i];
            array[i] = ((k >>> 24) & 0xff) | ((k >>> 8) & 0xff00) | ((k & 0xff) << 24) | ((k & 0xff00) << 8);
        }
    }
}

Related

  1. swap(final Object[] values, final int firstPosition, final int secondPosition)
  2. swap(final String a[], final int i, final int j)
  3. swap(final T[] arr, final int i, final int j)
  4. swap(final T[] arr, final int i, final int j)
  5. swap(int arr[], int i, int j)
  6. swap(int arrs[], int i, int j)
  7. swap(int i, int j, Integer[] unsorted)
  8. swap(int i, int j, String[] index)
  9. swap(int keys[], int values[], int a, int b)