Can't read HIGHBIT or LOWBIT of NIBble. Anyone knows how to do?
Flotul
Posts: 24
Hello,
To get more of the BS2's memory, I want to adress, one by one, every pair (4 in total as you know) of each byte.
I can't read either the HIGHBIT neither the LOWBIT of each NIBble. Here's the code. What's wrong with it?
' {$STAMP BS2}
' {$PBASIC 2.5}
ValeurMem VAR Byte
DATA %10110011
Main:
READ 0, ValeurMem
DEBUG BIN4 ? ValeurMem.NIB0 'shows the four last bits (LOWNIB) of the byte - ok
DEBUG BIN4 ? ValeurMem.NIB1 'shows the four first bits (HIGHNIB) of the byte - ok
DEBUG BIN2 ? ValeurMem.NIB0.BIT0 'should show the two last bits of the lowest nibble - but it doesn't...
DEBUG BIN2 ? ValeurMem.NIB0.BIT1 'should show the two first bits of the lowest nibble - but it doesn't...
DEBUG BIN2 ? ValeurMem.NIB1.BIT0 'should show the two last bits of the highest nibble - but it doesn't...
DEBUG BIN2 ? ValeurMem.NIB1.BIT1 'should show the two first bits of the highest nibble - but it doesn't...
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger
Savigny, SWITZERLAND (french speaking part)
To get more of the BS2's memory, I want to adress, one by one, every pair (4 in total as you know) of each byte.
I can't read either the HIGHBIT neither the LOWBIT of each NIBble. Here's the code. What's wrong with it?
' {$STAMP BS2}
' {$PBASIC 2.5}
ValeurMem VAR Byte
DATA %10110011
Main:
READ 0, ValeurMem
DEBUG BIN4 ? ValeurMem.NIB0 'shows the four last bits (LOWNIB) of the byte - ok
DEBUG BIN4 ? ValeurMem.NIB1 'shows the four first bits (HIGHNIB) of the byte - ok
DEBUG BIN2 ? ValeurMem.NIB0.BIT0 'should show the two last bits of the lowest nibble - but it doesn't...
DEBUG BIN2 ? ValeurMem.NIB0.BIT1 'should show the two first bits of the lowest nibble - but it doesn't...
DEBUG BIN2 ? ValeurMem.NIB1.BIT0 'should show the two last bits of the highest nibble - but it doesn't...
DEBUG BIN2 ? ValeurMem.NIB1.BIT1 'should show the two first bits of the highest nibble - but it doesn't...
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger
Savigny, SWITZERLAND (french speaking part)
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I made this same exercise one hour ago but one level "byte level". Here, it works. But since I have a need for only 4 (0 to 3) results (or possibilities), I want to make the same at nibble level.
Can you help? Following your suggestion, would itbe possible to addition those 2 bits? How?
' {$STAMP BS2}
' {$PBASIC 2.5}
ValeurMem VAR Byte
DATA %00010011
Main:
READ 0, ValeurMem
DEBUG BIN4 ? ValeurMem.LOWNIB, BIN4 ? ValeurMem.HIGHNIB
DEBUG ? ValeurMem.LOWNIB, ? ValeurMem.HIGHNIB
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger
Savigny, SWITZERLAND (french speaking part)
byte: 10100111
nibbles: 1010 0111
pairs: 10 10 01 11
^ my assumption of how you want to break it down
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
What is even stranger to me is that I could find the LOWNIB (NIB0) or HIGHNIB (NIB1) arguments in the help file under "Memory and Variables" ...
Is it really not possible?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger
Savigny, SWITZERLAND (french speaking part)
myVar VAR Nib
anyways, the bit modifiers only give you access to one bit at a time
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
What you can do is create a mask within each nibble %0011 or %1100 and shift right by 2 ">>2"
if you want to access the upper 2 bits of the nibble. This way, if you want you can assign a seperate
variable to the 2-bits that you are interested in. Hope this helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
THANK YOU
This is exactly what I needed.
I have never been dealing with the binary operators before so I didn't even know where to look to answer my question.
Again, Beau, thanks a lot. I really appreciate the time you must have spent on my problem.
Thank you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger
Savigny, SWITZERLAND (french speaking part)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
You can also do something like this to go the other direction...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
'·{$STAMP BS2}
' {$PBASIC 2.5}
temp··· VAR···· Byte
Main:
· temp = $A5
· DEBUG BIN8 temp, CR
· DEBUG REP " "\0, BIN2 temp.NIB1 >> 2, CR
· DEBUG REP " "\2, BIN2 temp.NIB1, CR
· DEBUG REP " "\4, BIN2 temp.NIB0 >> 2, CR
· DEBUG REP " "\6, BIN2 temp.NIB0, CR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Although your solution is more simple, it doesn't work as I need it. Have a look to what happens when you replace the "BIN2" argument by "BIN".
I'll stick to Beau's solution. In his case, I get for each pair of bits the decimal value calculated as if the byte would only be 2 bits long.
Example: %11100100 ($E4)
After the byte has been decomposed, the decimal values are:
- for bits 2 and 1 = 0
- for bits 4 and 3 = 1
- for bits 6 and 5 = 2
- for bits 8 and 7 = 3
Using caracters (elements) that have only 3 different possible values, I can now store FOUR TIMES MORE datas in the data memory of my BS2 (Bytes X 4)!
Isn't this great?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Roger
Savigny, SWITZERLAND (french speaking part)