[DM16] 8 bit reversal? Easiest way?
[DM16] 8 bit reversal? Easiest way?
I have a lot of 8 bit binary bytes to reverse like so
10110111 would become 11101101
Been trying to think of the best way to do this on the dm16
My Programming Skills are lacking in it but it’s still on my
Mind. Just wondered if anyone had seen such a routine as a quick search came up blank..
10110111 would become 11101101
Been trying to think of the best way to do this on the dm16
My Programming Skills are lacking in it but it’s still on my
Mind. Just wondered if anyone had seen such a routine as a quick search came up blank..
Re: 8 bit reversal? Easiest way?
Something like that:
At step 13 put the mode you want to have at the end of the routine.
Code: Select all
001 LBL A
002 HEX
003 8
004 STO I
005 CLX
006 LBL 0
007 X<>Y
008 RRC
009 X<>Y
010 RLC
011 DSZ
012 GTO 0
013 BIN
014 RTN
DM42: 00425 - DM41X: β00066 - WP43: 00042
Re: 8 bit reversal? Easiest way?
Fantastic ! Thanks it was the technique I was after- I’ll adapt that to exactly what I want . I actually wrote code for The Arduino project I’m writing to do it today but I really want the calculator to do it for the next batch of data I have and to have it as a stored program will be a brilliant help! The calculator rotates bits and converts brilliantly just needed to add this bit reversal ability to it - handy for flipping 8 bit graphics data left to right !
Re: 8 bit reversal? Easiest way?
How about this alternative? It doesn't involve a loop but requires the WSIZE to be at least 42:
It's twice as long.
Pauli
Code: Select all
001 LBL A
002 HEX
003 2
004 0
005 2
006 0
007 2
008 0
009 2
010 0
011 2
012 *
013 1
014 0
015 8
016 8
017 4
018 4
019 2
020 2
021 0
022 1
023 0
024 AND
025 3
026 F
027 F
028 RMD
029 RTN
Pauli
Last edited by pauli on Sat Aug 08, 2020 11:53 am, edited 1 time in total.
Re: 8 bit reversal? Easiest way?
X<>Y above - do you mean key program code 43.00 or 34 ?
Tried code but it just ran endlessly .. doing something wrong here I think..
Tried code but it just ran endlessly .. doing something wrong here I think..
Re: 8 bit reversal? Easiest way?
Here is the program with the key codes:
Code: Select all
001 43,22,A LBL A
002 23 HEX
003 8 8
004 44 32 STO I
005 43 35 CLX
006 43,22,0 LBL 0
007 34 X<>Y
008 43 d RRC
009 34 X<>Y
010 43 C RLC
011 43 23 DSZ
012 22 0 GTO 0
013 26 BIN
014 43 21 RTN
DM42: 00425 - DM41X: β00066 - WP43: 00042
Re: 8 bit reversal? Easiest way?
Very interesting, it's longer but much faster. However I can't figure out how it works. May you provide some explanation ?
DM42: 00425 - DM41X: β00066 - WP43: 00042
Re: 8 bit reversal? Easiest way?
Same here can’t work it out but it’s very clever !
Re: 8 bit reversal? Easiest way?
This second version does three steps (values are in hexadecimal):
The 64 bit word size isn't mandatory, 41 bits are sufficient. However, use 42 bits for signed calculations.
There is a whole family of algorithms like this where a longer multiplication is used to rearrange bits and optionally add them together.
Pauli
- Multiply by 202020202 which copies the byte five times across 41 bits.
- AND with 10884422010 which selects the bits in the correct positions based on ten bit bytes.
- Remainder 3FF (= 2^10-1 ) brings everything together.
Code: Select all
abcdefgh
10 00000010 00000010 00000010 00000010 *
----------------------------------------------
0 00000000 00000000 00000000 0000000a bcdefgh0 The all zero lines are omitted for brevity.
0 00000000 00000000 0000000a bcdefgh0 00000000
0 00000000 0000000a bcdefgh0 00000000 00000000
0 0000000a bcdefgh0 00000000 00000000 00000000
a bcdefgh0 00000000 00000000 00000000 00000000 +
----------------------------------------------
a bcdefgha bcdefgha bcdefgha bcdefgha bcdefgh0 Multiplication result.
1 00001000 10000100 01000010 00100000 00010000 AND
----------------------------------------------
a 0000f000 b0000g00 0c0000h0 00d00000 000e0000 AND result.
a 0000f000b0 000g000c00 00h000d000 00000e0000 Regrouping into units of ten bits.
1111111111 RMD
---------------------------------------------
00hgfedcba
There is a whole family of algorithms like this where a longer multiplication is used to rearrange bits and optionally add them together.
Pauli
Re: [DM16] 8 bit reversal? Easiest way?
Brilliant!