wood burning stoves 2.0*
The moose likes Java in General and the fly likes flipping bytes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "flipping bytes" Watch "flipping bytes" New topic
Author

flipping bytes

yash bhatnagar
Greenhorn

Joined: Dec 03, 2001
Posts: 16
i have to flip a integer value say if i have 1234 i want to flip it so that it becomes 4321 can any body help mein that.
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
Hello,
dividing by 10 and getting the remainder and division result we can have the Right most digits. Then multiply Rigth most digits with 1000s, 100s and 10s.
You can have the number in reverse manner.
Bin

Sarath Mohan
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2579

Originally posted by yash bhatnagar:
i have to flip a integer value say if i have 1234 i want to flip it so that it becomes 4321 can any body help mein that.

Simple solution would be to convert int to a String, reverse the String and convert it back to an integer using Integer.parseInt.
HTH,
- Manish
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Becareful of negatives though if using strings (-1234)
Sean
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: flipping bytes