Solved

how to reverse an array of bytes

Posted on 2004-08-16
3
235 Views
Last Modified: 2010-03-31
Is there any simple way of reversing an array of bytes?Any examples would be nice
Thanks In advance
0
Comment
Question by:inzaghi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
TrekkyLeaper earned 300 total points
ID: 11812462
public void reverse( byte[] b ) {
  for( int i = 0; i < b.length / 2; i++ ) {
    swap( b, i, b.length - i - 1 );
  }
}

private void swap( byte[] array, int a, int b ) {
  int temp = array[a];
  array[a] = array[b];
  array[b] = temp;
}
0
 
LVL 35

Expert Comment

by:girionis
ID: 11812478
If "bytes" is an array of bytes

for (int i=0; i<bytes.length; i++)
{
    bytes[i] = bytes[i] == 0 ? 1 : 0;
}
0
 
LVL 35

Expert Comment

by:girionis
ID: 11812492
bah.. ignore my comment... I was thinking bits instead :(
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question