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

bitwise operation....help

39
Hi.Given a number ,say 15, whose binary equivalent is 1111, how can the bit value of any position can be obtained using bitwise operators?Thanks for any help.

Jerico
Oct 7 '06 #1
1 1911
Banfa
9,065 Expert Mod 8TB
select the bit you want, say 3 bit (0100 = 0x04) AND the value with that bit and shift right by the number of 0 (2 in this case)

bit = (number & 0x04) >> 2;

bit will have either the value 0 or the value 1 depending on the value of the third bit in number.

Preferably bitwise operations should always be carried out on unsigned integers.
Oct 7 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Randell D. | last post by:
Why would one use bitwise operators? I can program in various languages in some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise operators before, but never understood why...
2
by: Joe Gonzalez | last post by:
Is it possible to perform bitwise operations in selects in DB2 8.1? In postgres I can say something like SELECT ... FROM <sometable> WHERE RecFlags && 0x08 <> 0 to get a bitwise and operation. I...
7
by: Jerry | last post by:
I want an algorithm that do arithmetic operations(divide,mutiply,add etc.)just using bitwise operators:<<,>>,&,|,^; For example,how "a/10" can be implemented. I just want a hint. Thanks.
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...
37
by: James Radke | last post by:
Hello, I found some code that I could use in my application on the web, but it is written in C#, and I would like to convert it to VB. And I am having problems with one section. Is there...
10
by: David R. | last post by:
I want to do bitwise operation on some large integers. For example, Response.Write CBool(2 AND 2^30) ' returns False Response.Write CBool(2 AND 2^31) ' CRASHED! Looks like the AND...
3
by: Marc | last post by:
I'm trying to set the first three bits to zero on a byte. For some reason, the compiler is casting the number peculiarly when I use the bitwise complement operator. Here's what I think should...
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...
3
by: Sakhtkoosh | last post by:
I have written a program in C environment. I need to do operation on codes with more than 64 elements whose values are 0 and 1. At first, I simulated it with an array in 2 dimension(n*m) but after...
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
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.