473,466 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Basic Bit Operation Question.

Hi every one,

I got very basic question, here i go:

Say i have 11001 11010 bits which are infact 10 bits. Now i want to
address every bit so if it is zero i would add one and if it is one
then i would be adding zero. Folks say it manchester coding.

Please note that left hand side just accept a single bit for every
operation.

how to do this , thanks.

Feb 12 '06 #1
6 2917
Jhon posted:
Hi every one,

I got very basic question, here i go:

Say i have 11001 11010 bits which are infact 10 bits. Now i want to
address every bit so if it is zero i would add one and if it is one
then i would be adding zero. Folks say it manchester coding.

Please note that left hand side just accept a single bit for every
operation.

how to do this , thanks.


I'll give a hand, rather than do the work for you.

unsigned long ManCode(unsigned long const x)
{
unsigned long result = x;

for(unsigned i = 0; i < 10; ++i)
{
if ( ! GetBit(x,i) ) ++result;
}

return result;
}

-Tomás
Feb 12 '06 #2
"Jhon" <jh**********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi every one,

I got very basic question, here i go:

Say i have 11001 11010 bits which are infact 10 bits. Now i want to
address every bit so if it is zero i would add one and if it is one
then i would be adding zero. Folks say it manchester coding.

Please note that left hand side just accept a single bit for every
operation.

how to do this , thanks.


I'm not quite sure what you're trying to do. Are you trying to 1's
compliment the bit stream?
11001 11010 becomes 00110 00101 ? Simply or the bits with 1.

0 | 1 = 1
1 | 1 = 0

Or are you trying to do something different?
Feb 12 '06 #3
There is an extremely sexy way to do this. Separate even from odd bits
by masking. Shift odd bits to the right by 1, so they align with the
even bits (right-most bit is 0). Now add the two.

Now separate every 2 bits by masking (masks 00110011... and 11001100...
) and shift the latter by two to the right. Add again.

Now separate every 4 bits by masking (masks 00001111.... and
11110000...) and shift by 4, add.

And so on (if you have only 10 bits, you can stop at 2x 8). Very fast,
very clever. It essentially adds individual bits in parallel. It's not
from me though;-)

Feb 12 '06 #4
Tomás wrote:
Jhon posted:
Hi every one,

I got very basic question, here i go:

Say i have 11001 11010 bits which are infact 10 bits. Now i want to
address every bit so if it is zero i would add one and if it is one
then i would be adding zero. Folks say it manchester coding.

Please note that left hand side just accept a single bit for every
operation.

how to do this , thanks.


I'll give a hand, rather than do the work for you.

unsigned long ManCode(unsigned long const x)
{
unsigned long result
for(unsigned i {
if ( ! GetBit(x,i) ) ++result;
}

return result;
}


The above routine returns the zero bit population count of its input. I
believe the original poster wants to encode a bit stream, replacing
each set bit with a set/unset bit pair and each unset bit with an
unset/set bit pair. So the bit sequence:

001100101

would be encoded as:

010110100101100110

A possible implementation (assuming stdint.h is available) would be to
encode the stream 16 bits at a time:

#include <stdint.h>

uint32_t ManCode( uint16_t x)
{
uint32_t result = 0;

for (int i = 0; i < 16; i++)
{
if (x & 0x8000)
result |= 0x02;
else
result |= 0x01;

x <<= 1;
result <<= 2;
}
return result;
}

Greg

Feb 12 '06 #5
Hi guys,
Thanks for posts, well i would just support Greg opinion. Yeah he
is quite sure how to do this and how manchester coding works.
I have solved the problem inthis way:

#define bit_get(p,m) ((p) & (m))
#define BIT(x) (0x01 << (x))

unsigned int delimiter = 0x33A // 0b11001 11010
int onebit=0;
bitcounter=9; //because it is 16 bit and i need MSB first so lets
start from bit 10;-)

while(1)
{

onebit = bit_get(delimiter, BIT((bitcounter)))

if(onebit & 0xff)
{
PORTE |= (1<<PE3);
PORTE &= ~(1<<PE3);
manchester =1;
}
else //manchester ==1
{
PORTE &= ~(1<<PE3);
PORTE |= (1<<PE3);
manchester =0;
}

onebit = 0;
bitcounter--;
if(bitcounter == 0) // just 10 times would be enough
break;
}

How about this! isn't sexy as well?

Feb 13 '06 #6
Jhon posted:
Hi guys,
Thanks for posts, well i would just support Greg opinion. Yeah he
is quite sure how to do this and how manchester coding works.
I have solved the problem inthis way:

#define bit_get(p,m) ((p) & (m))
#define BIT(x) (0x01 << (x))

When you use "#define" to create a function, it's called a "macro". Avoid
macros, especially when an inline function would do the trick.

template<typename T>
inline bool bit_get(T const o, unsigned const i)
{
return p & m;
}

unsigned Bit(unsigned x)
{
return 1 << x;
}

-Tomás
Feb 13 '06 #7

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

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
7
by: jesse | last post by:
In java, one constructor can call another constructor through this(...) for instance class foo { public: foo(int k) { this(k,false)}; foo(int k, boolean m){...}; }
4
by: LCAdeveloper | last post by:
I have had to move to Visual Studio.NET Pro. from Visual Basic 4.0 and am now starting to re-write our code. I was a bit surprised to find that Visual Basic.NET no longer supports fixed length...
1
by: Scott Haner via DotNetMonster.com | last post by:
Hey; I've done a decent amount of VB.net in University, but the next stage for a major project we have been asked to use 'modulization' and that the judges want to see as much code and functions...
7
by: Lau Lei Cheong | last post by:
Hello, Actually I think I should have had asked it long before, but somehow I haven't. Here's the scenerio: Say we have a few pages in an ASP.NET project, each of them needs to connect to...
25
by: Jhon | last post by:
Hi every one, I got very basic question, here i go: Say i have 11001 11010 bits which are infact 10 bits. Now i want to address every bit so if it is zero i would add one and if it is one...
2
by: Key9 | last post by:
Question about basic input output. HI All I am a new C++er Suppose I am designing a i/o device . system have screens . system have keyboards.
3
by: masood.iqbal | last post by:
In all the sample code snippets of try-catch code blocks that I have seen, the catch block does one of the following three things: 1). exits the program (after spitting out a cerr message) 2). ...
3
by: richie9648 | last post by:
Hi All I have created a macro which turns reports done by users into a format that is needed by me. The good this is that all the reports are in the same format. However my question is around...
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
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.