- Code: Select all
int x, y;
y = x[0] ^ x[2] ^ x[17];
There's not a snappy way to write that in C, is there? I'm going to have to do
- Code: Select all
y = x & 0x1 ^ x & 0x100 ^ x & 0x100000000000000000;
int x, y;
y = x[0] ^ x[2] ^ x[17];
y = x & 0x1 ^ x & 0x100 ^ x & 0x100000000000000000;
int a,b,c;
c = 0x1;
y = x & c ^ x & 0x4 ^ x & (c<<17);
int x, y;
y = x & 0x1 ^ x & 0x100 ^ x & (1<<17)
int TWOTOTHE(int x) {
return 1<<x;
}
y = x&TWOTOTHE(1) ^ x&TWOTOTHE(2) ^ x&TWOTOTHE(17);
Dwindlehop wrote:I'm surprised no one complained that I mixed binary and hexadecimal when initially describing the problem. ::sniff:: I'm so proud of you!
quantus wrote:Dwindlehop wrote:I'm surprised no one complained that I mixed binary and hexadecimal when initially describing the problem. ::sniff:: I'm so proud of you!
Wow, you're right, totally missed that. As for being proud of crappy debugging skillz, you must be smoking something. Anyways, I blame it on understanding your intent and leaving implementation up to the user (ie. you).
int TWOTOTHE(int x) {
return 1<<x;
}
y = x&TWOTOTHE(1) ^ x&TWOTOTHE(2) ^ x&TWOTOTHE(17);
int NTHBIT(int x, int n) {
return (1<<n & x)>>n;
}
int NTHBIT(int x, int n) {
return ((1<<n & x)>>n)&1;
}
sub bit_slice() {
$val = shift;
$pos = shift;
return ((1<<$pos & $val)>>$pos)&1;
}
Dwindlehop wrote:
- Code: Select all
int x, y;
y = x[0] ^ x[2] ^ x[17];
Dwindlehop wrote:
- Code: Select all
int TWOTOTHE(int x) {
return 1<<x;
}
y = x&TWOTOTHE(1) ^ x&TWOTOTHE(2) ^ x&TWOTOTHE(17);
sub bit_slice() {
$val = shift;
$pos1 = shift;
$pos2 = ( $#_ >= 0 ) ? shift : $pos1;
warn "YOU SUCK!!!" if ( $pos1 > 31 || $pos2 > 31 || $pos1 > $pos2 );
my $mask = (1<<($pos2-$pos1+1))-1;
return ( $val >> $pos1 ) & $mask;
}
If you're trying to point out that I suck, you won't get any arguments from me.quantus wrote:Looks to be Jonathan's error...
Users browsing this forum: No registered users and 2 guests