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. 6 2876
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
"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?
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;-)
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
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?
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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.
#...
|
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){...};
}
|
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...
|
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...
|
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...
|
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...
|
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.
|
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). ...
|
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...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |