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

Calculation of address

Hi, I have a vector of 18 bits (3 blocks of 6 bits each ), X = 010110 101011 111011, and I want to store for each block the first bit and the last bit (reading from left to right) in one variable, and from second bit to fifth bit in other variable. For example the first block, 010110, the first bit is 0 and the last bit is 0, so I will like to store in a variable A the number 0, for the other variable, the bit from two to five are 1011, so I will like to store in a variable B the number 11 (decimal), which is the same as 1011 (Binary). Thank you very much.
Aug 22 '06 #1
1 1620
D_C
293 100+
Expand|Select|Wrap|Line Numbers
  1. /*
  2. Given:   int data = "xxxx xxxx xxxx xxxx xxxx xxxx xxJK LMNP" (binary)
  3. Returns: int A = (J && P)
  4.          int B = KLMN =  8*K+4*L+2*M+N
  5. */
  6. int A = 0;
  7. int B = 0;
  8.  
  9. data &= 0b00111111; // data = JKLMNP
  10. A = data || 0b00000001; // P
  11. data >> 1; // data= JKLMN
  12. B =  data || 0b00001111; // KLMN
  13. data >> 4; // data = J
  14. A &= data; // || 0b00000001; // A = (P && J).
  15.            // The LOGICAL OR is unnecessary
Aug 22 '06 #2

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

Similar topics

8
by: Aspersion | last post by:
I'm building an ASP page that has a lot of text and graphics. There is a calculation facility on the page. The user enters several numbers in a form and presses a button to see the calculated...
22
by: KsAdmin | last post by:
I have a question which has had me stumped for a few days now. I have a form that I add the values of fields together and display the total in a total field. I have the calculations working...
0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
2
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that some of the...
3
by: Andrus | last post by:
Device connected to serial port accepts data packets in the form 02 0x57 ll ll 00 00 00 00 dd..dd cc cc 02 (1 byte ) is message prefix 0x57 (1 byte) is message type (W=Write) ll ll ( 2 bytes)...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
3
by: Marina | last post by:
I have a querie that needs to use multiple calculations (...I think...) Fields: TransID TransDate TransDescipt ClientID HoursBilled BillingRate
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
3
by: mattmao | last post by:
Okay, I was asked by a friend about the result of this limit: http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg Not n->zero but n-> + infinite I really...
2
by: Xafke | last post by:
Hello! I'm a very PHP newbie, and have a stupid problem.... This is the code I have trouble with: (PHP tags removed) round(( $number1 / $number2 )); The problem is that the result of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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...
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
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.