Bitwise operation
1
Name:
Anonymous
2010-06-09 5:28
How are simple operations like adding and subtraction represented using only bitwise operators such as &, |, ^,
>>, ~, and <<?
Also, do each of the bitwise operators perform at the same rate, or are some faster than others?
41
Name:
Anonymous
2010-06-09 16:36
>>40
That's not actually better than the one or two idiots hating on
Xarn because they're jealous of the attention he gets (or because they think their imageboard culture can be transplanted onto world4ch).
42
Name:
Anonymous
2010-06-09 16:38
>>41
Are you
Xarn ? I thought so.
43
Name:
Anonymous
2010-06-09 16:58
>>1
>>,
FUCKINGLY AMAZING
44
Name:
Anonymous
2010-06-09 17:18
45
Name:
Anonymous
2010-06-09 17:22
>>34
what the hell is that?
46
Name:
Anonymous
2010-06-09 17:26
>>20
Did you mean:
[code] int add(int a, int b) {
if (!a) return b;
return add((a & b) << 1, a ^ b);
}
47
Name:
Anonymous
2010-06-09 17:30
So I have found out a few things via googling
assume two unsigned integers a and b:[o]
a + b = ( ( a & b ) << 1 ) + ( a XOR b )[\o]
also
if ( a NAND b ) then ( a + b ) = a XOR b[o]
this is just saying if you don't have to carry while doing binary addition, then a + b is equal to a xor b [o] [\o][\o]
So I was thinking about the a + b = a xor b part and realized there must be some way to extrapolate a + b to a sum of terms that where we can then apply the a xor b thing.
Any ideas?
48
Name:
Anonymous
2010-06-09 18:01
assume a and b are the same size and are a list of bits
def a+b:
if size = 1: return (a&b, a^b)
else: return (first(a) + first(b) + first(rest(a)+rest(b)), rest(rest(a)+rest(b)))
49
Name:
Anonymous
2010-06-09 18:49
z = ((x * 0x0101010101010101ULL & 0x8040201008040201ULL) *
0x0102040810204081ULL >> 49) & 0x5555 |
((y * 0x0101010101010101ULL & 0x8040201008040201ULL) *
0x0102040810204081ULL >> 48) & 0xAAAA;
Used this snippet a couple days ago, if you know what it does from just looking at it then you know what you doing.
50
Name:
Anonymous
2010-06-09 19:14
>>49
It uses a bunch of meaningless magic numbers just to interpolate the bits of the result of some transformation of
x and
y as a
short.
51
Name:
Anonymous
2010-06-09 19:20
52
Name:
>>
!!50++bKT00Wlp00p
2010-06-10 0:58
53
Name:
Anonymous
2010-06-10 4:23
>>50
They aren't meaningless
!!
54
Name:
Anonymous
2010-06-10 12:07
>>49,53
Arithmetically interleaving bits
!! I don't care
!!
55
Name:
Anonymous
2010-06-11 15:17
No need to ask,
He's a smooth operator
56
Name:
Anonymous
2010-06-11 16:40
if (isSmoothOperator()) {
throw new ParadoxException();
}
57
Name:
Anonymous
2010-06-11 18:27
TOPICS IN ANALYSIS SMOOTH OPERATOR ALGEBRAS AND K-THEORY
58
Name:
Anonymous
2010-06-17 19:44
interesting problem you came across
#include <stdio.h>
int main()
{
int a,b,q=64;
for (a=0; a<q; a++) {
for (b=0; b<q; b++) {
if ((a + b) == (a ^ b))
printf("# ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # #
# # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # #
# # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# # # #
# #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # #
# # # #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# # # #
# #
# # # # # # # # # # # # # # # #
# # # # # # # #
# # # # # # # #
# # # #
# # # # # # # #
# # # #
# # # #
# #
# # # # # # # #
# # # #
# # # #
# #
# # # #
# #
# #
#
59
Name:
Anonymous
2010-06-17 19:46
#include <stdio.h>
int main()
{
int a,b,q=64;
for (a=0; a<q; a++) {
for (b=0; b<q; b++) {
if ((a + b) == ((a & b) << 1 ^ (a ^ b)))
printf("# ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # #
60
Name:
Anonymous
2010-06-17 19:52
>>58 represents the efficiency of the XOR (and OR too) operator as a substitute for the addition operator. It looks like a Sierpinski triangle.
61
Name:
Anonymous
2010-06-17 20:43
uintmax_t plus(uintmax_t a, uintmax_t b)
{ return a && b ? plus(a ^ b, (a & b) << 1) : a | b; }
62
Name:
Anonymous
2010-06-18 0:04
Subtract:
int Sub (int X, int x)
{
return (((~X & x) << 1) ?
Sub((~(~X & ~x) & ~(X & x)),((~X & x) << 1)) :
(~(~X & ~x) & ~(X & x)));
}
63
Name:
Anonymous
2010-06-18 1:13
#include <stdio.h>
int main()
{
int a,b,q=64;
float c = 0.0;
fgetc(stdin);
for (a=0; a<q; a++) {
c = a/2;
while (c > 0) {
printf(" ");
c--;
}
for (b=0; b<q; b++) {
if ((a + b) == (a ^ b))
printf("# ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
65
Name:
Anonymous
2010-12-21 18:58
66
Name:
Anonymous
2011-01-31 20:38
<-- check em dubz
Newer Posts