473,395 Members | 1,688 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,395 software developers and data experts.

How to access the individual bits of a value stored?

how to access the bits of a value stored in memory as such?
Sep 27 '10 #1
4 3860
ashitpro
542 Expert 512MB
you may like to see bitwise operators in C/C++

http://www.cs.cf.ac.uk/Dave/C/node13.html
Sep 27 '10 #2
Oralloy
988 Expert 512MB
Either that, or you can use a union to map a bitmaped structure on top of your input value, like so:

Expand|Select|Wrap|Line Numbers
  1.  
  2. union myConverter
  3. {
  4.   long  baseValue
  5.   struct
  6.   {
  7.     unsigned  bit0 : 1;
  8.     unsigned  bit1 : 1;
  9.     unsigned  bits2to31 : 30;
  10.   };
  11. } convert;
  12.  
  13. convert.baseValue = 12345;
  14. convert.bit0 = 0;                // baseValue now = 12344
  15.  
Sep 27 '10 #3
Banfa
9,065 Expert Mod 8TB
But a bit field structure like that is very platform dependent. If you moved your code to another platform or compiler even you have no guarantee that the result would be baseValue = 12344 because the order that bit fields are placed in the base field is platform defined.
Sep 27 '10 #4
Oralloy
988 Expert 512MB
Banfa,

You're right. They are platform dependent. Just like that long is guaranteed to be a minimum of 32 bits.

It's a darned good observation, and one I haven't been bitten hard by (yet).

On the other hand, it's about the best way to prevent coding errors - when it's used well and properly. Oh yes, and tested.

I've seen projects take weeks long hits when people hand code bit extractions and get it wrong. Thus, my preferred solution is to bit-field map. I know its not absolutely portable, however in my experience, it has been adequate. That's about all I can say.

Yes, projects that map across architectures have to be much more careful in their structure. That's where guys like you and me come in to "get it right".

Cheers!
Sep 27 '10 #5

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

Similar topics

2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
1
by: Boltar | last post by:
Hello, I am relatively new to C#. There is a particular address in memory on my computer that stores a string value. The address is 57E777. Does anyone know how I can retrieve the string...
1
by: Kevin C | last post by:
Is the IsPostBack property value stored in viewstate?
2
by: Daniel Passwater via DotNetMonster.com | last post by:
I'm receiving a byte that contains the pass/fail test results of multiple tests. The first six bits are set. I need to read each of them separately. Is there an elegant way to do this? Thanks in...
2
by: DeWitt Phillips | last post by:
First let me say thank you. I am trying to extract the last value entered into a database column without having to read through every value stored in the column. Is that something that is easy to...
4
by: jenn | last post by:
Hi Anyone knows how to access to a value of a row in a datalist. Something like this in datagrid Dim str = MyDataGrid.Cell(0).tex I would like something like this Dim str =...
2
by: Ironman | last post by:
Dear Access Developers: I have an interesting problem that I hope someone could suggest how to solve: I have the following Report: Col-1 Col-2 -------- ------- 483.3 100
1
by: shovan mohanty | last post by:
Hi , Can anybody convert below access query into equivalent stored procedure. Also please advice in the below query,user defined function of VBA i.e anneeSelection41510() has been used in the...
9
by: Vbbeginner07 | last post by:
Want to change the value stored in the bold, it's a code to calculate the payroll. If txttr.Text = "" Then Form2.txttamt.Text = "" MsgBox "enter the tax rate", vbOKOnly, "ERROR" ...
1
by: Krishna | last post by:
How do I access individual fields in csv using python? Please let me know ASAP as its real urgent for me. Thanks for your help Krishna
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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:
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.