Read array in sequence, and convert it's contents into single variable?
Hello, say I have 32 bit array, in each of it's "cells" is written either 1 or 0. I want to read this array in a way, that these cells add next to each other. Say, content of first 4 cells is "1" "1" "0" "1". How can I convert it into single byte variable, which will read as "1101" ?. If there were string variables, then task would be simple, by just reading current array position into string variable, and adding to itself. But in PBP we don't have string variables, how should I ?
Re: Read array in sequence, and convert it's contents into single variable?
like this maybe
Code:
myarray var byte[4] ; a 32 bit array
nbyte var byte ;result
inx var byte ;start index in array
x var byte
arraywrite myarray,[105,100,10,116] ; fill array
inx=3 ; start a bit 3
nbyte=0 ;clr result
for x= 0 to 3 ;get the 4 bits
nbyte.0[x] = myarray.0[x+inx]
next
serout2 PORTa.0,84, [13,10,"nb ",bin4 nbyte ]
Re: Read array in sequence, and convert it's contents into single variable?
How do you want to work with it afterwards? did you want to process it as decimal 1101 or binary 1101 or just "string" 1101?
Re: Read array in sequence, and convert it's contents into single variable?
I want to convert it to decimal and use in that way.
Re: Read array in sequence, and convert it's contents into single variable?
Sorry, I'm confused on this. You want to take each nibble and convert it to a decimal value, or???
Re: Read array in sequence, and convert it's contents into single variable?
No, imagine array consists of "1" "0" "1" "1" digits, I want to "merge" them into one binary variable, which I will convert to decimal later.
Re: Read array in sequence, and convert it's contents into single variable?
so where is the problem ?
what have you tried ?