473,668 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what does it do?

what does it do?
#define BLACKBOX(x) ((x)&((x)-1))

Nov 14 '05 #1
8 1807
puzzlecracker wrote:
what does it do?
#define BLACKBOX(x) ((x)&((x)-1))


For unsigned integers x and signed integers x in 2s complement
with x>(integer type's minimum value), this clears the least
significant set bit.
It also works for 1s complement signed integers and
x!=0 && x!=1 && x>(integer type's minimum value)

-Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #2

puzzlecracker wrote:
what does it do?
#define BLACKBOX(x) ((x)&((x)-1))


Clears the least significant set bit in x. This works on all unsigned
numbers and all signed numbers (except "sign-magnitude" negative even
numbers).

Nov 14 '05 #3
Luke Wu wrote:
puzzlecracker wrote:
what does it do?
#define BLACKBOX(x) ((x)&((x)-1))

Clears the least significant set bit in x. This works on all unsigned
numbers and all signed numbers (except "sign-magnitude" negative even
numbers).


.... and except for x==T_MIN where T is the respective integer type;
in the case of 1s complement you cannot rely on 0 not switching
its representation, so x==0 and x==1 are not guaranteed to work
either.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #4
> puzzlecracker wrote:
what does it do?
#define BLACKBOX(x) ((x)&((x)-1))

What do you think it does?

If you want to 'test' clc, at least try to be original.

Michael Mair wrote:
For unsigned integers x and signed integers x in 2s complement
with x>(integer type's minimum value), this clears the least
significant set bit.
It also works for 1s complement signed integers and
x!=0 && x!=1 && x>(integer type's minimum value)


No, consider the following (high bit is sign-bit):

1c or 2c(C99) sm
x : 10000000 10000000 10000000 01111111
x - 1: 10000000 01111111 10000000 10000000
& : 10000000 00000000 10000000 00000000

The result could be a trap representation.

Note also that C89 potentially allows negative representations
beyond 2c, 1c and sm.

--
Peter

Nov 14 '05 #5
On 21 Feb 2005 13:08:16 -0800, "Luke Wu" <Lo***********@ gmail.com> wrote:

puzzlecracke r wrote:
what does it do?
#define BLACKBOX(x) ((x)&((x)-1))


Clears the least significant set bit in x. This works on all unsigned
numbers and all signed numbers (except "sign-magnitude" negative even
numbers).


Inputting the integer '8' causes the "function" to return zero. Not
suprizing, since the original poster is a known troll.

Nov 14 '05 #6
bk***@ncf.ca (Raymond Martineau) writes:
On 21 Feb 2005 13:08:16 -0800, "Luke Wu" <Lo***********@ gmail.com> wrote:
puzzlecrack er wrote:
what does it do?
#define BLACKBOX(x) ((x)&((x)-1))


Clears the least significant set bit in x. This works on all unsigned
numbers and all signed numbers (except "sign-magnitude" negative even
numbers).


Inputting the integer '8' causes the "function" to return zero. Not
suprizing, since the original poster is a known troll.


8 has only one bit set. Clearing that bit, which is necessarily
the least significant set bit, yields 0. Thus, this is correct
behavior.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #7
jjf

Raymond Martineau wrote:
On 21 Feb 2005 13:08:16 -0800, "Luke Wu" <Lo***********@ gmail.com> wrote:

puzzlecracke r wrote:
what does it do?
#define BLACKBOX(x) ((x)&((x)-1))
Clears the least significant set bit in x. This works on all unsignednumbers and all signed numbers (except "sign-magnitude" negative evennumbers).


Inputting the integer '8' causes the "function" to return zero.


Yes, exactly as Luke said. What's your point?
Not suprizing, since the original poster is a known troll.


What are you on about?

Nov 14 '05 #8


Peter Nilsson wrote:
puzzlecrack er wrote:
what does it do?
#define BLACKBOX(x) ((x)&((x)-1))


What do you think it does?

If you want to 'test' clc, at least try to be original.


Ack.
Michael Mair wrote:
For unsigned integers x and signed integers x in 2s complement
with x>(integer type's minimum value), this clears the least
significant set bit.
It also works for 1s complement signed integers and
x!=0 && x!=1 && x>(integer type's minimum value)
No, consider the following (high bit is sign-bit):

1c or 2c(C99) sm
x : 10000000 10000000 10000000 01111111
x - 1: 10000000 01111111 10000000 10000000
& : 10000000 00000000 10000000 00000000

The result could be a trap representation.


Just to make sure: Your "no" is referring to the fact that we
could get a trap representation? Or do you mean that the
formulation "least significant bit" is incorrect?
I am not sure what you want to say with the sign-magnitude example
-- most certainly the "lowest" bit of x is not cleared.

Note also that C89 potentially allows negative representations
beyond 2c, 1c and sm.


Thank you for the reminder (mostly, I assume C99 _restrictions_
for everything and am surprised if C89 is not as strict).
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
33875
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
3
2991
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a waste of time to start writing yet another IDE and so am now thinking in terms of new features/plug-ins for existing systems. Right now I mostly use Komodo Personal and it's pretty close to being what I want. They don't currently support plug-ins,...
65
5348
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++ language. A C++ interface installation IS ABOUT THE C++ LANGUAGE! The language does not possess the ability to handle even simple file directory manipulation. Those wise people that created it did not take care of it. So, BOOST is a portable...
125
14709
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
3
29675
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification says: "The 'visibility' property takes the value 'collapse' for row, row group, column, and column group elements. This value causes the entire row or column to be removed from the display, and the space normally taken up by the row or column to...
7
2676
by: Dan V. | last post by:
Situation: I have to connect with my Windows 2000 server using VS.NET 2003 and C# and connect to a remote Linux server at another company's office and query their XML file. Their file may be updated every hour or so. How can I do this easily? I would like to use secure communication even encryption if possible. I would query and insert locally only the newest records found in that XML file to an xml or MS access db.
44
4200
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there must be many know the answer here. thanks
121
10030
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
13
5036
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
669
25864
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8381
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8797
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8583
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8656
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2791
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.