My efforts exploring Barker codes with bit manipulation.
It is not quite there yet and a first pass at this as my morning coding workout.
Reference image from here:
https://www.radartutorial.eu/08.transmitters/pic/kor7.print.jpg
Code:
// Barker Code using Bit Manipulation
// v1.0.0
// GLV 2021-07-15
//References:
// https://www.radartutorial.eu/08.transmitters/Barker%20Code.en.html
// https://www.radartutorial.eu/08.transmitters/pic/kor7.print.jpg
// https://en.wikipedia.org/wiki/Barker_code
// It is not quite there yet but a first pass at this as my morning coding workout.
void setup()
{
size(600, 400);
background(0);
// Some working Barker codes
//int n = 7;
//int bo = 0b1110010;
//int bm = 0b1111111;
//int n = 11;
//int bo = 0b11100010010;
//int bm = 0b11111111111;
int n = 13;
int bo = 0b1111100110101;
int bm = 0b1111111111111;
int b1 = bo<<n;
println(binary(bo, 2*n));
println(binary(b1, 2*n));
int bx;
int l;
int sum;
for (int s = 0; s<2*n+1; s++)
{
bx = (~(bo^(b1>>>s))) & ((bm<<n)>>>s);
l = n-abs(s-n);
sum = 0;
for (int k = 0; k<n; k++)
{
sum += (bx>>>k)&0x01;
}
int bs = abs(2*sum-l);
//println(nfs(s, 2), binary(bx, n), l, sum, bs);
println(nfs(s, 2), binary(bx, n), bs);
strokeWeight(10);
stroke(255, 255, 0);
point(20*s+40, height-(20*bs+100));
}
}
Output:
Console output:
I am sharing code as is as an example of bit manipulation for the Gallery.
I am not asking for help with this… it was just for fun!
:)