Zeroing bits

Thread Solved

Join Date: Jan 2008
Posts: 343
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 43
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Whiz

Zeroing bits

 
0
  #1
15 Days Ago
Is this the proper way to zero the first 12 bits of an address?

  1. void *ans = (void*)((unsigned long)addr & ((0UL - 1) ^ 0xfff));

Where addr is any user process memory address..

Note this method works...I just want to know if there is a better way
Last edited by gerard4143; 15 Days Ago at 12:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 64
Reputation: kolosick.m188 is an unknown quantity at this point 
Solved Threads: 12
kolosick.m188's Avatar
kolosick.m188 kolosick.m188 is offline Offline
Junior Poster in Training
 
0
  #2
15 Days Ago
I'd just do a bitwise shift left 12 then a bitwise shift right 12
There are 10 types of people in the world, those who get this, those who don't, and those who thought this was binary.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 343
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 43
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Whiz
 
0
  #3
15 Days Ago
Originally Posted by kolosick.m188 View Post
I'd just do a bitwise shift left 12 then a bitwise shift right 12
Don't you mean the other way around? Maybe I have a different meaning for first 12
Last edited by gerard4143; 15 Days Ago at 1:54 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 64
Reputation: kolosick.m188 is an unknown quantity at this point 
Solved Threads: 12
kolosick.m188's Avatar
kolosick.m188 kolosick.m188 is offline Offline
Junior Poster in Training
 
0
  #4
15 Days Ago
Here's what I mean
1010101010101111
First twelve is 101010101010
Shift left twelve gives
1111000000000000
Shift right twelve then gives
0000000000001111
There are 10 types of people in the world, those who get this, those who don't, and those who thought this was binary.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 343
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 43
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Whiz
 
0
  #5
15 Days Ago
Originally Posted by kolosick.m188 View Post
Here's what I mean
1010101010101111
First twelve is 101010101010
Shift left twelve gives
1111000000000000
Shift right twelve then gives
0000000000001111
O.K. what I meant was the opposite to what you have here...either way your method works..Thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,334
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 234
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c
 
0
  #6
15 Days Ago
Originally Posted by gerard4143 View Post
Is this the proper way to zero the first 12 bits of an address?
void *ans = (void*)((unsigned long)addr &  ((0UL - 1)  ^ 0xfff));
Where addr is any user process memory address..

Note this method works...I just want to know if there is a better way
That kind of masking works just fine; it might be expressed more simply:
void *ans = (void*)((unsigned long)addr &  ~0xfffUL);
(At least as far as manipulating bits of an integer. I don't know what address manipulation will get ya.)
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC