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

Bit manipulation

Hi!

We would like to see if C# (1.1) has any API to manipulate bit in that
way:

For example,
send a variable to it, like a INT64 and ask that function is such bit
is 1 or 0;

like...

Int64 test = 255;

bool bit = CheckBit(test, 5);

and that CheckBit would return if the 5th bit is 1 or 0...

We know how to write that function, and it's simple, but we always
prefer to use the standard API, and we don't know if C# 1.1 has that
already.

Thanks in advance

Dec 18 '06 #1
3 3459
For 32-bit, note that there is BitVector32... no 64-bit counterpart
AFAIK...

Marc
Dec 18 '06 #2
As far as I know there is no real .NET equivalent of what you are
looking for, so you probably won't be able to do it with a single
function call, but it wouldn't be overly complicated to implement
yourself.
You could use
"bool bit = Convert.ToString(test,2)[4] == '1'"
to achieve the desired result.
Otherwise you could create a bitmask and XOR it with the passed
variable (probably the fastest way, if performance matters).

Sincerely,
Kevin Wienhold

jfbaro schrieb:
Hi!

We would like to see if C# (1.1) has any API to manipulate bit in that
way:

For example,
send a variable to it, like a INT64 and ask that function is such bit
is 1 or 0;

like...

Int64 test = 255;

bool bit = CheckBit(test, 5);

and that CheckBit would return if the 5th bit is 1 or 0...

We know how to write that function, and it's simple, but we always
prefer to use the standard API, and we don't know if C# 1.1 has that
already.

Thanks in advance
Dec 18 '06 #3
But it starts to get a lot scrappier (plus more cycles) than just
using bitwise arithmetic... and you may want to watch out for endian
issues relating to BitConverter...

For tthe 64-bit case (in fact, most cases), you'd be better off with a
quick "shift, and, equals" test... the CPU is generally pretty
optimised for such operations. To refute my own suggestion, even
BitVector32 adds a few hurdles in terms of dealing with masks instead
of a clean bit index.

Marc
Dec 18 '06 #4

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

Similar topics

2
by: Marcus | last post by:
I am having some problems with trying to perform calculations on time fields. Say I have a start time and an end time, 1:00:00 and 2:30:00 (on a 24 hour scale, not 12). I want to find the...
4
by: Rune Johansen | last post by:
Hi. I'm doing some image manipulation in an applet using the example code on this page: http://www.akop.org/art/pixels3.htm However, I really want an application rather than an applet, I just...
3
by: Sam | last post by:
Hello, in my coding work I'm going to using a lot of matix manipulation, just basic matrix addition, multiplication, Gaussian method solving for roots, least square... But I don't know if there's...
9
by: I. Kobrinsky | last post by:
I'm new here. I started a personal password-program, a trial that includes username, logincounter and password. So my intention is to hide pwd while tipping. So I'm thinking about two popular...
9
by: Job | last post by:
Hi, I would like to find out what ASP/ASP.net can do with image manipulation. Does ASP have built in functions (eg. after upload to server) to manipulate images, like rotate, scale, crop etc.?...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
8
by: shotokan99 | last post by:
i have this situation. i have a query string: http://www.myquerystring.com?x=xxxxx what this url does is it will return or start downloading a .png file. what i wanted to do is trap this png...
0
by: L'eau Prosper Research | last post by:
Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases new TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set. L'eau Prosper Market...
0
by: L'eau Prosper Research | last post by:
NEW TradeStation 8 Add-on - L'eau Prosper Market Manipulation Profiling Tools Set By L'eau Prosper Research Press Release: L'eau Prosper Research (Website: http://www.leauprosper.com) releases...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
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...

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.