473,385 Members | 2,069 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,385 software developers and data experts.

((i & 1) == 1)

public static bool isodd(int i)
{
return ((i & 1) == 1);
}

can someone explain me how this is working
Jun 27 '08 #1
5 2813
On 2008-06-26, joso <jo**@hi.t-com.hrwrote:
public static bool isodd(int i)
{
return ((i & 1) == 1);
}

can someone explain me how this is working
It's a simple test for oddness on an integer value. Any integer value that is
odd will have a one in the ones column... So, the result of a bitwise and of
any integer value and one, can tell you if it is odd or not.

1111 & 0001 = 1
0111 & 0001 = 1
0100 & 0001 = 0
1110 & 0001 = 0

--
Tom Shelton
Jun 27 '08 #2
An integer is a basic type having a number of binary bits.

Depending on your processer architecture this might be 32 or 64 bits.

The binary and (&) operator performs a bitwise "AND" operation on the
integer which effectively removes all but the least significant bit of the
integer. This may be 1 or 0 depending on the value.

In the case that it is indeed 1, the number is odd.

Hope this was easily understood.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"joso" <jo**@hi.t-com.hrwrote in message
news:g4**********@ss408.t-com.hr...
public static bool isodd(int i)
{
return ((i & 1) == 1);
}

can someone explain me how this is working
Jun 27 '08 #3
Bob Powell [MVP] wrote:
An integer is a basic type having a number of binary bits.

Depending on your processer architecture this might be 32 or 64 bits.
In C# an int is always 32 bit.

Arne
Jun 27 '08 #4


"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:48***********************@news.sunsite.dk...
Bob Powell [MVP] wrote:
>An integer is a basic type having a number of binary bits.

Depending on your processer architecture this might be 32 or 64 bits.

In C# an int is always 32 bit.

Arne
He didn't write 'int' but 'integer'. An integer is a mathematical concept,
an int in C# is an alias for a System.Int32 which is an integer represented
in the architecture as 32 bits as opposed to an Int64.

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

Jun 27 '08 #5
Joe Fawcett wrote:
"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:48***********************@news.sunsite.dk...
>Bob Powell [MVP] wrote:
>>An integer is a basic type having a number of binary bits.

Depending on your processer architecture this might be 32 or 64 bits.

In C# an int is always 32 bit.
He didn't write 'int' but 'integer'. An integer is a mathematical
concept, an int in C# is an alias for a System.Int32 which is an integer
represented in the architecture as 32 bits as opposed to an Int64.
How do you think that he think about integer as a mathematical type
when he write "An integer is a basic type having a number of binary
bits" ?

Besides it would be even worse if it were the case. Believing that
a mathematical concept depends on processor architecture to be
either 32 or 64 bit.

Arne
Jun 27 '08 #6

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

Similar topics

9
by: Collin VanDyck | last post by:
I have a basic understanding of this, so forgive me if I am overly simplistic in my explanation of my problem.. I am trying to get a Java/Xalan transform to pass through a numeric character...
1
by: DrTebi | last post by:
Hello, I have the following problem: I used to "encode" my email address within links, in order to avoid (most) email spiders. So I had a link like this: <a...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
4
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&amp;" when it gets used as a querystring in the url EG: ...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
7
by: John Nagle | last post by:
I've been parsing existing HTML with BeautifulSoup, and occasionally hit content which has something like "Design & Advertising", that is, an "&" instead of an "&amp;". Is there some way I can get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.