Take a look here for a bit of theory: http://mindprod.com/jgloss
Main Topics
Browse All Topicsi need to represent the binary arithmetic operators for integer in terns of bitwise operators...
i.e i need to represent +, - , * , / in terms of &,|,^, ~ etc...
how to do this...
thanks for the help
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Take a look here for a bit of theory: http://mindprod.com/jgloss
BitSet internally implements a bit-vector that can grow dynamically while when you're using arrays you get a fixed size. So the choice comes down to whether the size is going to grow dynamically or not.
Not sure if you could do a 2 + 3 operation using bitwise operators. There should be a way that I probably don't know. But you can take a look here: http://c.ittoolbox.com/cod
There is no easy way to do it. Take a look here:
http://mindprod.com/jgloss
Also for subtraction take a look here: http://mathforum.org/libra
IF you go to the home page of the above page you will find loads of examples on binary.
Maheshexp makes my point very well. I did my best to represent what you want to show in code, but as you see, most of the actual mechanics of this type of code is lower level or theory based. Backgroiund knowledge of assembly, cpu register, & binary math operations helps understand this as it is somewhat cryptic when viewed from a high level language perspective.
Best wishes, robb
at last found a way to find the fast modulo...it's intresting and fast...have a look at this link
http://mersenneforum.org/s
can things be possible liek this (not same like this, but to say...) to make fast multiplication division etc....
i found something from Knuth's Seminumerical algorithms....numbers can be multiplied faster if it is expressed in the form
(A1 * 2^n + A2 ) = A
(B1 * 2^n + B2 ) = B
i.e (A1 * 2^n + A2 ) * (B1 * 2^n + B2) = (A1 * B1)*2^(2n) + ((A1 * B2) + ( A2 * B1)) * 2^n + A2 * B2
after reductions
= (A1*B1)*(2^(2n)+2^n) + (A1-A2)*(B2-B1)*2^n + (A2*B2)*(2^n+1)
= (A1*B1)<<(2n) + (A1*B2)<<n + (A1-A2)*(B2-B1)<<n + (A2*B2)<<n + (A2*B2)
Thus the most expensive operation ---multiplication---
need only be computed three times:
1. A1*B1
2. (A1-A2)*(B2-B1)
3. A2*B2
if tired using BigIntegers,it's really faster, but when A1,A2 or B1,B2 is significantly big, it slows down , but it is really faster than normal multiplication provided by BigInteger
Yes I know the ^ symbol. Thing is I can't see how A1*B1 could be represented using & or some other bitwise operator for example. I really don't think computers use bitwise operators to do addition for instance but rather a built in mechanism that adds each bit seperately. But again I am not very good at low-level stuff, I might be wrong.
Business Accounts
Answer for Membership
by: rsalzmannPosted on 2004-05-25 at 12:03:31ID: 11155137
See if this helps:
mNumeral);
omNumeral) ;
om randomNumeral) {
m randomNumeral) {
import java.util.*;
public class BitWiseDemo {
private static final int MAXNEG_INT = -2147483648;
private static final int MAXPOS_INT = 2147483647;
private static final long MAXNEG_LONG = -9223372036854775808L;
private static final long MAXPOS_LONG = 9223372036854775807L;
//experiment with this value to see the effect on
//the shift operations.
private static final int SHIFT_FACTOR = 3;
public static void main(String[] args) {
Random randomNumeral = new Random();
performIntOperations(rando
performLongOperations(rand
}
private static void performLongOperations(Rand
long randomNumeralLongx = randomNumeral.nextLong();
long randomNumeralLongy = randomNumeral.nextLong();
longOperation("-1L", -1L);
longOperation("+1L", +1L);
longOperation("maxpos", MAXPOS_LONG);
longOperation("maxneg", MAXNEG_LONG);
longOperation("l", randomNumeralLongx);
longOperation("~l", ~randomNumeralLongx);
longOperation("-l", -randomNumeralLongx);
longOperation("m", randomNumeralLongy);
longOperation("l & m", randomNumeralLongx & randomNumeralLongy);
longOperation("l | m", randomNumeralLongx | randomNumeralLongy);
longOperation("l ^ m", randomNumeralLongx ^ randomNumeralLongy);
longOperation("l << shiftFactor", randomNumeralLongx << SHIFT_FACTOR);
longOperation("l >> shiftFactor", randomNumeralLongx >> SHIFT_FACTOR);
longOperation("(~l) >> shiftFactor", (~randomNumeralLongx) >> SHIFT_FACTOR);
longOperation("l >>> shiftFactor", randomNumeralLongx >>> SHIFT_FACTOR);
longOperation("(~l) >>> shiftFactor", (~randomNumeralLongx) >>> SHIFT_FACTOR);
}
private static void performIntOperations(Rando
int randomNumeralIntx = randomNumeral.nextInt();
int randomNumeralInty = randomNumeral.nextInt();
intOperation("-1", -1);
intOperation("+1", +1);
intOperation("maxpos", MAXPOS_INT);
intOperation("maxneg", MAXNEG_INT);
intOperation("i", randomNumeralIntx);
intOperation("~i", ~randomNumeralIntx);
intOperation("-i", -randomNumeralIntx);
intOperation("j", randomNumeralInty);
intOperation("i & j", randomNumeralIntx & randomNumeralInty);
intOperation("i | j", randomNumeralIntx | randomNumeralInty);
intOperation("i ^ j", randomNumeralIntx ^ randomNumeralInty);
intOperation("i << shiftFactor", randomNumeralIntx << SHIFT_FACTOR);
intOperation("i >> shiftFactor", randomNumeralIntx >> SHIFT_FACTOR);
intOperation("(~i) >> shiftFactor", (~randomNumeralIntx) >> SHIFT_FACTOR);
intOperation("i >>> shiftFactor", randomNumeralIntx >>> SHIFT_FACTOR);
intOperation("(~i) >>> shiftFactor", (~randomNumeralIntx) >>> SHIFT_FACTOR);
}
static void intOperation(String s, int i) {
System.out.println(
s + ", int: " + i + ", binary: ");
System.out.print(" ");
for(int j = 31; j >=0; j--)
if(((1 << j) & i) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
}
static void longOperation(String s, long l) {
System.out.println(
s + ", long: " + l + ", binary: ");
System.out.print(" ");
for(int i = 63; i >=0; i--)
if(((1L << i) & l) != 0)
System.out.print("1");
else
System.out.print("0");
System.out.println();
}
}
~robb