473,508 Members | 2,247 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 1797
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:

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).


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:
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).


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[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof 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:

puzzlecracker 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:
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.


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
33326
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...
3
2980
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...
65
5280
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++...
125
14542
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...
3
29661
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...
7
2651
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...
44
4126
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...
121
9908
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...
13
5001
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
25396
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...
0
7229
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,...
1
7061
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...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
5057
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...
0
4716
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...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
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...

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.