• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

flipping bytes

 
yash bhatnagar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Manish Hatwalne
Ranch Hand
Posts: 2591
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Becareful of negatives though if using strings (-1234)
Sean
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic