I'm trying to learn how right >> and left << shift operations in c++. I've reading some articles in
internet and some topics here, but I'm still confused. I'm trying to code a LFSR (Linear Feedback 122 People Chatting
1 Shift Register) based on users input who should give the length, seed and polynomial tap position
as input to the LFSR code. JavaScript
2 hours ago - rlemon
The code would be like this:
#include <iostream>
#include <string> Python
#include <cmath> 2 hours ago - Kevin
int main()
{ Related
string seed;
unsigned int length, pos; 1697 What is the difference between #include
<filename> and #include “filename”?
cout << "Type the length and the seed" << endl;
cin >> length >> seed; 1947 How do you set, clear, and toggle a single
cout << "Polynomial tap positions" << endl; bit?
cin >> pos;
2478 What are the differences between a pointer
//Creating array with the LFSR size variable and a reference variable in C++?
unsigned int *sizee = new unsigned int[length];
//Convert the seed from char to int 1150 What are bitwise shift (bit-shift) operators
for (unsigned int i = 0; i < length; i++) { and how do they work?
sizee[i] Questions
= seed[i] - Developer
'0'; Jobs Tags Users Search… Log In Sign Up
} 1436 How can I profile C++ code running in
//Shifting Linux?
unsigned int seq = std::pow(2,length)-1;
for (unsigned int i = 1; i <= seq ; i++) { 4254 The Definitive C++ Book Guide and List
//Shift Operation here
//Show user the value 1143 What is the effect of extern “C” in C++?
}
7502 What is the “-->” operator in C++?
delete[] sizee;
1138 Easiest way to convert int to string in C++
return 0;
} 1476 C++11 introduced a standardized memory
model. What does it mean? And how is it
How can I shift bits, for example, the seed 00001 in a LFSR of length = 5 and Tap positions (Xor going to affect C++ programming?
positions) 5 and 3 (x^5+x^3+1) to the right? I expect to obtain something like: 00001 > 10000 >
01000 > 00100 > 10010, and so on, until the end of the loop, considering Fibonacci as architecture Hot Network Questions
type.
How old is the oldest light visible from Earth?
c++ bit-manipulation bit-shift
Does sslstrip work on websites only which uses
both HTTP and HTTPS?
share improve this question edited Jul 24 '15 at 18:37 asked Jul 24 '15 at 16:23
How do I explain a unicorn discharging powerful
Leonardo Alves electricity at a distance?
17 1 9
How to install two applications/packages
simultaneously?
Can you elabortate for users who don't know what a LFSR is? Surely, your problem is more basic than LFSR. –
Booming Blade trigger timing
Walter Jul 24 '15 at 16:40
How to override an unpluggable parent theme
1 std::pow(2,length) makes me sad – harold Jul 24 '15 at 16:41
function?
@Walter LFSRs are using to generate pseudo-random numbers "automatically", you can find more explanation Does writing matter a lot in research?
here: en.wikipedia.org/wiki/Linear_feedback_shift_register. Harold, I don't get your point. Im new to c++, sorry.
– Leonardo Alves Jul 24 '15 at 18:21 How resilient is the Staff of the Magi?
@LeonardoAlves you're doing a bitshift using floating point exponentiation, on the "silly scale" that's just one Can wind instruments be played out of tune?
step better than converting to a string in binary, appending zeroes, and then parsing it back – harold Jul 27 '15
Why should a software QA engineer need to learn
at 18:05
JavaScript?
integers are usually written in big-endian form, with bit 0 on the right and the highest bit on the Second argument of Internal`DoubleToString
left Up go the bits!
Those lead to two important things when you use integers for LFSRs: Converting succession type from Gavelkind to
Primogeniture in early game
bit i of the LFSR becomes bit i-1 of the integer How can you run a program that is bigger than
RAM?
the right shift of the LFSR becomes a left shift of the integer.
How can I list running bash scripts by the name of
so your basic LFSR step becomes: the script?
I got it. But, what I really trying to understand is what (seed << 1) does. It moves the value 1 to left seed
times? – Leonardo Alves Jul 24 '15 at 18:32
1 @LeonardoAlves: (seed << 1) shifts the value from seed 1 bit position to the left. So bit 1 comes from bit
0 of seed, bit 2 from bit 1, etc. A 0 is shifted in to bit 0. – Chris Dodd Jul 24 '15 at 18:35
Oh, I got it. Thank you @Chris – Leonardo Alves Jul 24 '15 at 18:43
add a comment
First off, you will not be able to use the >> and << operators as you have an array of ints.
The << and >> operators are only defined for numeric data types. You should switch to using just an
0
int.
Thats what I have in mind. But, what would be the seed type? and how would I define "the positions" to XOR
them? – Leonardo Alves Jul 24 '15 at 18:47
add a comment
Your Answer
By posting your answer, you agree to the privacy policy and terms of service.
Not the answer you're looking for? Browse other questions tagged c++ bit-manipulation bit-shift or
ask your own question.
STACK OVERFLOW STACK OVERFLOW COMPANY STACK EXCHANGE Blog Facebook Twitter LinkedIn
BUSINESS NETWORK
Questions About
Talent Technology
Jobs Press
Ads Life / Arts
Developer Jobs Directory Work Here
Enterprise Culture / Recreation
Salary Calculator Legal
Science
Help Privacy Policy site design / logo © 2018 Stack Exchange Inc;
Other user contributions licensed under cc by-sa 3.0
Mobile Contact Us with attribution required. rev 2018.4.9.29787