473,792 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's the tilde in a &= ~b ?

Hi everyone,

in this thing I inherited there's a statement like this:

a &= ~b;

where a is an int and b has been declared this way:

const b = 0x0002;

and thus is probably an int as well.

My question: What's the tilde doing there? Is that standard C++? What
does it mean?

Cheers &= thanks
Benjamin
Apr 4 '06 #1
12 18003

"Benjamin B." <no*****@today. com> wrote in message
news:e0******** **@online.de...
Hi everyone,

in this thing I inherited there's a statement like this:

a &= ~b;

where a is an int and b has been declared this way:

const b = 0x0002;

and thus is probably an int as well.
(If I recall, implicit int's are no longer used. It should specify const
int, for clarity if nothing else.)

My question: What's the tilde doing there? Is that standard C++? What
does it mean?

That's the "bitwise complement" operator. It reverses the bits (1s become
0s, and vice-versa). (You really should get yourself a good C++ book, by
the way.)

-Howard
Apr 4 '06 #2

Benjamin B. wrote:
Hi everyone,

in this thing I inherited there's a statement like this:

a &= ~b;

where a is an int and b has been declared this way:

const b = 0x0002;

and thus is probably an int as well.

My question: What's the tilde doing there? Is that standard C++? What
does it mean?


If you are familiar with gates, which all these bitwise operators are,
it is NOT. NOT inverts its input so when it has power it is off, when
it doesn't it is on. Power is 1, no power is 0. Output is 0 where
there is a 1 and 1 where there is a 0 in the input.

Apr 4 '06 #3
Howard wrote:
"Benjamin B." <no*****@today. com> wrote in message
news:e0******** **@online.de...
Hi everyone,

in this thing I inherited there's a statement like this:

a &= ~b;

where a is an int and b has been declared this way:

const b = 0x0002;

and thus is probably an int as well.
(If I recall, implicit int's are no longer used. It should specify const
int, for clarity if nothing else.)


Sure it should. It's on the todo list, there are more of those.
My question: What's the tilde doing there? Is that standard C++? What
does it mean?


That's the "bitwise complement" operator. It reverses the bits (1s become
0s, and vice-versa).


Thanks a lot!
(You really should get yourself a good C++ book, by
the way.)


Uhm possible ... though I'll rather concentrate on the standard library
and the likes if I have the choice ...

Cheers
Benjamin
Apr 4 '06 #4
This operation is often used to clear a bit / flag in some kind of
status variables.

In your example the ~ operator (bitwise complement) sets all bits to 1
except the bit that corresponds to 0x0020.

Then the & operator (AND) will unset only the bit 0x0020 in your
variable a since this is the only bit set to 0.

Henryk

Apr 4 '06 #5
Noah Roberts wrote:
Benjamin B. wrote:
Hi everyone,

in this thing I inherited there's a statement like this:

a &= ~b;

where a is an int and b has been declared this way:

const b = 0x0002;

and thus is probably an int as well.

My question: What's the tilde doing there? Is that standard C++? What
does it mean?
If you are familiar with gates, which all these bitwise operators are,
it is NOT. NOT inverts its input so when it has power it is off, when
it doesn't it is on. Power is 1, no power is 0. Output is 0 where
there is a 1 and 1 where there is a 0 in the input.


I think you are talking about ! (logical NOT), it is in the same family as:
&&
||
==
!=
< <==


operator~ is bitwise NOT or complement. It applies a NOT to each and
every bit, it is in the same family as:
&
|
^
<<


For unsigned integers, at least.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Apr 4 '06 #6

Ben Pope wrote:
Noah Roberts wrote:
Benjamin B. wrote:
Hi everyone,

in this thing I inherited there's a statement like this:

a &= ~b;

where a is an int and b has been declared this way:

const b = 0x0002;

and thus is probably an int as well.

My question: What's the tilde doing there? Is that standard C++? What
does it mean?
If you are familiar with gates, which all these bitwise operators are,
it is NOT. NOT inverts its input so when it has power it is off, when
it doesn't it is on. Power is 1, no power is 0. Output is 0 where
there is a 1 and 1 where there is a 0 in the input.


I think you are talking about ! (logical NOT), it is in the same family as:
&&
||
==
!=
<
>

<=
>=
No, but those are boolean operators that behave in similar ways. If
you wish to think of them in those terms as well it might help. At
least &&, ||, and ! may very well be implemented as gates.
operator~ is bitwise NOT or complement. It applies a NOT to each and
every bit, it is in the same family as:
&
AND
|
OR
^
NAND
<< >>


I can't think of any gate that will perform these functions.

Apr 4 '06 #7

"Benjamin B." <no*****@today. com> wrote in message
news:e0******** **@online.de...
Howard wrote:

(You really should get yourself a good C++ book, by
the way.)


Uhm possible ... though I'll rather concentrate on the standard library
and the likes if I have the choice ...


You lost me there. What do you mean by the "standard library"? The
"standard template library" [STL]? The STL is a set of templates, written
in C++. If you're referring to the C++ run-time library, then you're
talking about a given compiler vendor's implementation of the C++ language
features (such as I/O, basic math functions, etc.). Perhaps you're talking
about some on-line Help system in your compiler's IDE?

In any case, you need some source of information which will tell you how to
program in C++, what its basic syntax and rules are, and what the language
features are and how to use them. Sounds like a book to me... you got some
other way to learn all that?

-Howard
Apr 4 '06 #8

Howard wrote:
>> (You really should get yourself a good C++ book, by
the way.)


Uhm possible ... though I'll rather concentrate on the standard library
and the likes if I have the choice ...


You lost me there. What do you mean by the "standard library"? The
"standard template library" [STL]? The STL is a set of templates, written
in C++. If you're referring to the C++ run-time library, then you're
talking about a given compiler vendor's implementation of the C++ language
features (such as I/O, basic math functions, etc.). Perhaps you're talking
about some on-line Help system in your compiler's IDE?


Have you really not heard of the C++ standard library? If not, perhaps
you need to follow your own good advice and get yourself a good book as
well. I highly recommend Josuttis' The C++ Standard Library. Or
perhaps I misunderstood you (I seem to do that at times).

Best regards,

Tom

Apr 4 '06 #9
Hello,

Noah Roberts wrote:
^
NAND


^ is bitwise XOR, not a bitwise NAND
<<
>>


I can't think of any gate that will perform these functions.


If you take wiring and a constant zero bit...

Bernd

Apr 4 '06 #10

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

Similar topics

0
1111
by: CHristian Niss | last post by:
hi there, in a lot of user controls we are using "~" in server tags to reference objects like images <img src="~/images/something.gif" runat="server" />. with framework 1.0 the tilde got replaced by "/virtualdir" for example. now in framework 1.1 tilde is replaced with relative paths like "../../" this makes a lot of trouble, especially when you dynamically load user controls to an aspx-page. it seems that this relative "../.."-path...
1
3723
by: MB2 | last post by:
I have code in a User Control for an image button like this: <asp:ImageButton id="__0" runat="server" text="Delete" ImageUrl="~/Images/ImageLibrary/icon_delete.gif" /> This used to work and it would display the image properly. However, since installing the latest service pack for the .NET Framework 1.1, the tilde seems to be expanding improperly. The code that is expanded to shows this: <input type="image"...
10
1613
by: Shawn | last post by:
Hi, For a few years, I have been developing each of my clients websites using a seperate web site (unique IP) to solve problems with relative URL's between my local dev station and the production server. Recently, I have needed to collaborate with other developers using Source Safe. But, in order to get source safe working properly, you really need to be working in virtual directories of the default web site.
9
3322
by: Jared Tullis | last post by:
We have an .NET 1.1 application running on 4 2K3 load balanced servers (using WLBS). IIS has the .NET aspnet_isapi.dll mapped as a wildcard application map. The web.config points *.html to a HttpHandler of our design. This setup serves over a million page views daily with almost no hassle whatsoever. We have brought a few affiliates onto our system who have URLs still floating in Google, Y! and other search engines from before they...
3
4321
by: Karo | last post by:
I have troubles with tilde (~) character on my host. It gets replaced by server name instead of domain name from where redirect is coming from. Code HttpContext.Current.Response.Redirect("~/Install/Install.aspx?mode=Install") redirects to host domain. Does anyone know where the problem could be? .NET framework, IIS or somewhere else?
1
2220
by: Mythran | last post by:
In other web servers, more specifically apache and even non-web servers you can use the tilde character to specify the root directory, or home. Before I go reinventing the wheel (by parsing a tilde in the web controls for iis) is there a setting that allows similar functionality in IIS? Thanks, Mythran
4
14608
by: ibiza | last post by:
Hi all, I have a problem which I don't understand with the "~" mark in a NavigateUrl property of an asp:HyperLink. I have this in a master page, to build the standard menu (rMenuItems is a Repeater): Protected Sub rMenuItems_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
2
1517
by: jbolty | last post by:
There have been a few threads talking about using the tilde ~, to reference the webroot path. My problem though is handling an unexpected tilde in a url. this url: http://localhost/mysite/~Default.aspx returns this error:
3
8197
by: John Nagle | last post by:
I have XML replies in a DOM which contain entity escapes, like "&amp;". What's the proper way to replace them with the ordinary characters? Preferably something that will work in most browsers? I know about ".innerText", but that's not portable; some browsers convert escapes when reading from innerText and some don't. John Nagle
0
9670
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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
10211
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
10159
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
10000
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...
0
9033
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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
6776
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();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.