linear feedback shift register

I am dealing with Linear Feedback Shift Register. Most of the codes that I found are written in C. Is anyone has an example of LFSR using C++?

Thank you.
Bit twiddling C code should still be valid C++. Is there some reason you can't use that code you found as-is?
I am working with Xilinx HLS tool. Basically I wrote all the algorithms in C++. I want LFSR to be the input of my algorithm. So, I think, the whole work should be written in C++. That is why I need the LFSR to be written in C++.

If C++ and C can be combined, how it can be worked? Is there any example?
Post the LFSR code you found.
If C++ and C can be combined, how it can be worked? Is there any example?

the operators are the same. ~ (bit-not), ^ (bit xor), << shift, etc.. all the same
and those work on whatever integer types (but be very very cautious with signed values)
bitfields are the same. (but, not sure many use in c++ anymore?)
bitset is c++ only.

above that, c++ lets you wrap this stuff in classes or make it cleaner...

or, in a nutshell, the two are identical down in the details and only differ a bit when you decide how to wrap it up.

example... what language is this?
unsigned int a,b;
a = 3;
b = 5;
a ^= b;

… now when you chose to write out a with printf or c++ you have sort of picked a language assuming you don't use printf in your c++ code...

and, on top of this, c++ compilers can let you put a C file in and compile them all together. If you have something in C that just works, wrap in a function and call from c++. If your C code has a main function, you may have to convert that to not be main, but nothing major will need to be done.
Last edited on
Topic archived. No new replies allowed.