News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Line Continuation

Started by streborc, Jan 24, 2026, 05:21 PM

Previous topic - Next topic

streborc

I'm working on a program that stores binary values in a large array and then calculates several Hamming Code parity bits from many non-contiguous array entries.  The format is:

parity_bit[i] = (array_val[a] + array_val[d] + ... + array_val[z])//2
The list of "array_val[n]" is longer than what conveniently fits on a single line.  There doesn't seem to be any permutation of commas, underscores or curly brackets that allows the line to be parsed and continued on the next line unless I've overlooked the obvious.  The only solution I've found is to break the expression into multiple intermediate sums in the form:

parity_bit[i] = array_val[a] + array_val[d] + ... + array_val[f]
parity_bit[i] = parity_bit[i] + array_val[m] + array_val[p] + ... + array_val[r]
parity_bit[i] = parity_bit[i] + array_val[s] + array_val[u] + ... + array_val[x]

parity_bit[i] = parity_bit[i]//2

I haven't found any applicable solutions in the forum threads I've searched, aside from naming the array with minimal characters.  Is there a better way to do this?

RGV250

Hi,
According to the manual page 51 (Positron8) the line continuation only works after a comma delimiter.

Bob

trastikata

#2
Quote from: streborc on Jan 24, 2026, 05:21 PMI'm working on a program that stores binary values in a large array and then calculates several Hamming Code parity bits from many non-contiguous array entries.  The format is:
parity_bit[i] = (array_val[a] + array_val[d] + ... + array_val[z])//2

Just to make clear, you store binary values (1 or 0) in separate elements of a byte array? This is very inefficient way yo do that.

Anyway, if you deal with non-contiguous array entries I'd design the code a different way:
- use LUTs for each specific sequence of elements you want to calculate the parity for
- in each LUT the first element is the length of the LUT
- then use one Procedure to calculate any of the sequences created by the LUTs

I don't know the exact parity calculation mechanism you are using, but this code example should give you an idea how to structure you code listing:

    pParity = ParityCalc(Seq2)
End

Proc ParityCalc(mySequence As Dword), Bit
    Dim wElement As Word
    Dim wCounter As Word     
    Clear Result
    For wCounter = 1 To CRead16 mySequence[0]   'Loop through sequence LUT
        wElement = CRead16 mySequence[wCounter] 'Get current array element number
        Result = Result + array_val[wElement]   'Read value from that array element and calculate parity or do something else
    Next
EndProc

Dim Seq1 As Flash16 = 11,30,20,10,100,5,300,280,320,1,0,99
Dim Seq2 As Flash16 = 4,310,28,199,5
Dim Seq3 As Flash16 = 15,10,155,78,66,230,45,35,145,138,238,8,299,44,67,124
'....
Dim array_val[345] As Byte
Dim pParity As Bit



streborc

Trastikata -

Thanks for your reply and suggestions.  I apologize for my abbreviated description of the issue I'm working on, but I did not want to discourage potential replies with a mind-numbing rambling.

Agreed, storing a series of bits in a byte array is inefficient memory-wise, but inasmuch as my application involves bit-by-bit use, it seems the most simple.  I'm working on a project that involves time code transmissions from the WWVB "atomic clock".  Time information is transmitted in two formats simultaneously, the legacy method being PWM/ASK and the newer method being BPSK.  Both methods embed time data in a 60 second frame comprising 60 bits of 1 second duration.  The BPSK encoding uses 26 bits to represent the current minute of the current century (which is BTW 13,713,014 (0x0D13E76) as I'm writing this).  Appended to the 26 bits of time data are 5 parity bits derived from a Hamming Code calculation method.

Each of the 5 parity bits is calculated by summing//2 a unique set of 15 of the 26 data bits.  While my code initially computes the current minute in hexadecimal form -- the 0x0D13E76 -- I store it bit by bit in the array[60], and then produce 5 summations of the designated 15 bits stored in the array.  I implemented an alternate method that masks the hexadecimal time quantity 0x0D13E76 with each of the 5 Hamming vectors (for example, 0x0B3E375), and then masks the result with 0x0000001, shifts left, and sums for 26 iterations.  This produces an identical set of 5 parity bits, but seems to waste considerable time, since my original method requires only 15 summations from array stored bit values to derive each parity bit.

In addition to the 31 time + parity bits, there are 14 fixed value sync bits, 11 bits related to daylight savings time transitions, and a couple unused bits that comprise the 60 bit time code sequence.  Storing all this in an array rather than recreating each bit as its need arises keeps things simple for the task at hand, and within the scope of my primitive coding abilities.

Thanks again for your reply.