# Reversing

• 11-04-2008, 12:35 AM
Reversing
how do you reverse an int, and add it to another int...
• 11-04-2008, 12:39 AM
xcallmejudasx
use the modulus operator and create a new string of the reversed int then concat, convert the second int to string, concat together and print.
• 11-04-2008, 01:04 AM
Norm
Quote:

reverse an int
what is reversing an int? What base are you using?
If the int (in binary is) 1010 (decimal 10)
then reversed would be 0101 (decimal 5)
• 11-04-2008, 05:57 AM
Eranga
Quote:

Originally Posted by Norm
what is reversing an int? What base are you using?
If the int (in binary is) 1010 (decimal 10)
then reversed would be 0101 (decimal 5)

I'm confused too.

More specifically this process is call, bitwise complement.
• 11-04-2008, 03:15 PM
Norm
Poor example. Let me expand it.
Looking at the contents of an int in binary could be:
000001010
reversing the order of the bits would be
010100000
Not the compliment which would be:
111110101
• 11-04-2008, 05:28 PM
Eranga
Ya, looking at your example for a minute I thought it's compliment.
• 11-04-2008, 10:30 PM
like

int reverse = 15;

how do i reverse int reverse to 51?
• 11-04-2008, 11:05 PM
hardwired
Code:

```        int n = 15;         String s = String.valueOf(n);         String reverse = "";         for(int i = s.length()-1; i >= 0; i--) {             reverse += String.valueOf(s.charAt(i));         }         int reversed = Integer.parseInt(reverse);         System.out.printf("n = %d  reversed = %d%n",                           n, reversed);```
• 11-05-2008, 12:52 AM
Norm
How do you expect the OP to think and learn programming if you give him the code? He'll be great with select, copy and paste, but what will he do when you're not there?
I'd think a student would get more satisfaction figuring out how to do something himself.
• 11-05-2008, 04:29 AM
Eranga
Quote:

Originally Posted by Norm
How do you expect the OP to think and learn programming if you give him the code? He'll be great with select, copy and paste, but what will he do when you're not there?
I'd think a student would get more satisfaction figuring out how to do something himself.

I agreed with you Norm. Most of newbies in Java just looking a code, not showing any attempt themselves. I don't know why they are doing like that. Most of the time, if they not found any solution in quick time just left the forum and registered in another. For me it's too bad habit.
• 11-05-2008, 05:10 AM
hahahah, well you know what lol, i am teaching myself java by trying, i've been working on figuring out how to do that for close to 2 months, and i havn't found a way, all the codes i show you or ask help with are codes i have tried for at least a month, and gotten too frusterated to keep working.
• 11-05-2008, 05:19 AM
Eranga
Ok, but the thing is I cannot see any code segment you have post here.
• 11-06-2008, 12:09 AM