473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Bitwise AND etc

mdh
If one searches the forum for bitwise operators there are numerous
questions and very good answers to the perenial question about what
these operators do and why we need them.
So, having looked at all these, I approached K&R 2.9 headily!! ...but
not for long :-(

Quote:
The bitwise AND operator & is often used to mask off some set of bits;
for example,
n=n & 0177;
sets to zero all but the low-order 7 bits of n.

End Quote;

Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.
However this has not gotten me very far.
Thanks in advance.

May 10 '06 #1
17 3305
mdh wrote:
If one searches the forum for bitwise operators there are numerous
questions and very good answers to the perenial question about what
these operators do and why we need them.
So, having looked at all these, I approached K&R 2.9 headily!! ...but
not for long :-(

Quote:
The bitwise AND operator & is often used to mask off some set of bits;
for example,
n=n & 0177;
sets to zero all but the low-order 7 bits of n.

End Quote;

Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.
However this has not gotten me very far.
Thanks in advance.

0177 is an octal (base 8) number, so it is 01111111 in binary.

--
Ian Collins.
May 10 '06 #2
"mdh" writes:
The bitwise AND operator & is often used to mask off some set of bits;
for example,
n=n & 0177;
sets to zero all but the low-order 7 bits of n.

End Quote;

Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.
However this has not gotten me very far.


It's octal so it means 1 111 111.
May 10 '06 #3
mdh

Ian Collins wrote:

0177 is an octal (base 8) number, so it is 01111111 in binary.

oops...

Well, I am glad I asked!! Ok...now it makes sense.
thank you.

May 10 '06 #4
mdh

osmium wrote:
It's octal so it means 1 111 111.


Thank you.

May 10 '06 #5
mdh wrote:
If one searches the forum for bitwise operators there are numerous
questions and very good answers to the perenial question about what
these operators do and why we need them.
So, having looked at all these, I approached K&R 2.9 headily!! ...but
not for long :-(

Quote:
The bitwise AND operator & is often used to mask off some set of bits;
for example,
n=n & 0177;
sets to zero all but the low-order 7 bits of n.

End Quote;

Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.


Why you would think that 0177 represents that bit pattern eludes me.
The number 7 (octal, decimal, or hex) is 111 binary.
The octal number 0177 is, quite obviously, 01111111 binary.
At the risk of appearing to belabor the obvious, I'll point out the
grouping:
0(flagging as octal) 1 7 7
binary equivalents: 001 111 111
May 10 '06 #6
Martin Ambuhl <ma*****@earthlink.net> writes:
mdh wrote:

[snip]
Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.


Why you would think that 0177 represents that bit pattern eludes me.


He undoubtedly didn't realize that the leading 0 makes it an octal
constant. 177 decimal is 10110001 binary.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 10 '06 #7
In article <%F**************@newsread4.news.pas.earthlink.net >,
Martin Ambuhl <ma*****@earthlink.net> wrote:
mdh wrote:
If one searches the forum for bitwise operators there are numerous
questions and very good answers to the perenial question about what
these operators do and why we need them.
So, having looked at all these, I approached K&R 2.9 headily!! ...but
not for long :-(

Quote:
The bitwise AND operator & is often used to mask off some set of bits;
for example,
n=n & 0177;
sets to zero all but the low-order 7 bits of n.

End Quote;

Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.


Why you would think that 0177 represents that bit pattern eludes me.


The OP clearly thought that 0177 was a base 10 number.

177 (base 10) == 0xB1 (base 16) == 10110001 (base 2)
May 10 '06 #8

"mdh" <md**@comcast.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
If one searches the forum for bitwise operators there are numerous
questions and very good answers to the perenial question about what
these operators do and why we need them.
So, having looked at all these, I approached K&R 2.9 headily!! ...but
not for long :-(

Quote:
The bitwise AND operator & is often used to mask off some set of bits;
for example,
n=n & 0177;
sets to zero all but the low-order 7 bits of n.

End Quote;

Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.
However this has not gotten me very far.
Thanks in advance.


Others have pointed out that the conversion is incorrect. My advice is to
learn hexadecimal since it is easily converted to binary. If you need to
use octal or decimal, get a calculator to convert to hex or binary.
Rod Pemberton
May 11 '06 #9
"Rod Pemberton" <do*********@bitfoad.cmm> writes:
"mdh" <md**@comcast.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
If one searches the forum for bitwise operators there are numerous
questions and very good answers to the perenial question about what
these operators do and why we need them.
So, having looked at all these, I approached K&R 2.9 headily!! ...but
not for long :-(

Quote:
The bitwise AND operator & is often used to mask off some set of bits;
for example,
n=n & 0177;
sets to zero all but the low-order 7 bits of n.

End Quote;

Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.
However this has not gotten me very far.
Thanks in advance.


Others have pointed out that the conversion is incorrect. My advice is to
learn hexadecimal since it is easily converted to binary. If you need to
use octal or decimal, get a calculator to convert to hex or binary.


octal is even easier to convert to binary than hexadecimal is.

1 -> 001
7 -> 111
0177 -> 001 111 111

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 11 '06 #10

"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
"Rod Pemberton" <do*********@bitfoad.cmm> writes:
"mdh" <md**@comcast.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
If one searches the forum for bitwise operators there are numerous
questions and very good answers to the perenial question about what
these operators do and why we need them.
So, having looked at all these, I approached K&R 2.9 headily!! ...but
not for long :-(

Quote:
The bitwise AND operator & is often used to mask off some set of bits;
for example,
n=n & 0177;
sets to zero all but the low-order 7 bits of n.

End Quote;

Could someone perhaps just demonstrate this with an example? (I have
tried to make sense of the fact that 0177 is, I believe '10110001'.
However this has not gotten me very far.
Thanks in advance.


Others have pointed out that the conversion is incorrect. My advice is to learn hexadecimal since it is easily converted to binary. If you need to use octal or decimal, get a calculator to convert to hex or binary.


octal is even easier to convert to binary than hexadecimal is.

1 -> 001
7 -> 111
0177 -> 001 111 111


It simply doesn't fit nicely within a multiple of a nybble.

Rod Pemberton
May 12 '06 #11
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rod Pemberton wrote:
"Keith Thompson" <ks***@mib.org> wrote in message

[snip]
octal is even easier to convert to binary than hexadecimal is.

1 -> 001
7 -> 111
0177 -> 001 111 111


It simply doesn't fit nicely within a multiple of a nybble.


But, for those machines that use 9bit bytes, octal is ideal. You get three
octets per byte :-)

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEZR7cagVFX4UWr64RAoEjAKCz6osDvQUdwRcxPnT+6n pigBKoXwCeJk5N
9TY1nxlUppWuuJUK7VO1//U=
=7FzG
-----END PGP SIGNATURE-----
May 13 '06 #12
Lew Pitcher said:
But, for those machines that use 9bit bytes, octal is ideal. You get three
octets per byte :-)


I'm not quite sure what you mean here, but you don't mean octets. Three
octets is 24 bits, which would be - er - 2.66+ 9-bit bytes.

Perhaps you mean - well, not nybbles exactly... Trybbles, perhaps?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 13 '06 #13
jjf

Richard Heathfield wrote:
Lew Pitcher said:
But, for those machines that use 9bit bytes, octal is ideal. You get three
octets per byte :-)


I'm not quite sure what you mean here, but you don't mean octets. Three
octets is 24 bits, which would be - er - 2.66+ 9-bit bytes.

Perhaps you mean - well, not nybbles exactly... Trybbles, perhaps?


And we all know that trybbles cause nothing but trouble ...

May 13 '06 #14
jj*@bcs.org.uk writes:
Richard Heathfield wrote:
Lew Pitcher said:
> But, for those machines that use 9bit bytes, octal is ideal. You get three
> octets per byte :-)


I'm not quite sure what you mean here, but you don't mean octets. Three
octets is 24 bits, which would be - er - 2.66+ 9-bit bytes.

Perhaps you mean - well, not nybbles exactly... Trybbles, perhaps?


And we all know that trybbles cause nothing but trouble ...


Yeah, it's that funky unary multiplication operator that always
confuses people.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 13 '06 #15
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Richard Heathfield wrote:
Lew Pitcher said:
But, for those machines that use 9bit bytes, octal is ideal. You get three
octets per byte :-)


I'm not quite sure what you mean here, but you don't mean octets. Three
octets is 24 bits, which would be - er - 2.66+ 9-bit bytes.

Perhaps you mean - well, not nybbles exactly... Trybbles, perhaps?


Sorry, yes. The proper name escaped me

I meant those three-bit things that can hold one of eight possible values.
"Trybbles", you say? OK, I guess, but you know that I have trouble with
trybbles. They keep multiplying and multiplying and pretty soon, I'm up to my
navel in them.

:-)

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEZUFiagVFX4UWr64RAjwiAJ4reJYoaqWUfg+SeZm1Py xPGIbrVACgrU9P
gt+zgMkUbU2phDYP3HLooWU=
=qf+d
-----END PGP SIGNATURE-----
May 13 '06 #16
Lew Pitcher <lp******@sympatico.ca> writes:
Rod Pemberton wrote:
"Keith Thompson" <ks***@mib.org> wrote in message [snip]
octal is even easier to convert to binary than hexadecimal is.

1 -> 001
7 -> 111
0177 -> 001 111 111


It simply doesn't fit nicely within a multiple of a nybble.


But, for those machines that use 9bit bytes, octal is ideal. You get three
octets per byte :-)


I still find the octal notation useful for numbering things that come
in groups of 8. For example in digital electronics, quite often you
might have, say, 64 outputs arranged in 8 groups of 8 (because the
chips have "byte-wide" busses.. So you can number them in octal, and
know that 023 is output #3 in bank #2. It is nice to have this
supported directly in C.
--
Lew Pitcher


I think your sig separator needs an extra " ".

--

John Devereux
May 13 '06 #17
Groovy hepcat Richard Heathfield was jivin' on Sat, 13 May 2006
00:07:43 +0000 in comp.lang.c.
Re: Bitwise AND etc's a cool scene! Dig it!
Perhaps you mean - well, not nybbles exactly... Trybbles, perhaps?


How about triptet?

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
May 14 '06 #18

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

Similar topics

6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
8
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the...
9
by: Christopher Weaver | last post by:
I know that the bitwise AND of 8 and 4 will return 0 or false and the bitwise AND of 8 and 9 will return 1 or true but I don't know how to write the synax for it in C#. I have a value that ranges...
5
by: noridotjabi | last post by:
I'm learning to program in C and any tutorial or book that I read likes to briefly touch on birdies operators and then move on without giving any sort of example application of them. Call me what...
2
by: Mark Rae | last post by:
Hi, This isn't *specifically* an ASP.NET question, so I've also posted it in the ADO.NET group - however, it's not too far off-topic... Imagine a SQL Server 2005 database with a table with an...
3
by: Jay Ruyle | last post by:
I'm trying to figure out a way to list several items in a listbox and let the user select any number of items in the listbox. I have tried to code in the items as bitwise items but all it stores...
5
by: Gigs_ | last post by:
Can someone explain me bitwise expression? few examples for every expression will be nice x << y Left shift x >y Right shift x & y Bitwise AND x | y Bitwise OR x ^ y Bitwise XOR (exclusive...
45
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can...
29
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.