Helle wrote:@Michael: I get 1 0 1 0 1 0 1
1 
.
The only error can be seen(?) in my brain, I haven't read careful enough

and thought, something like that has to be found...
Code: Select all
liczba=25
numer=3
Debug Asc(Mid(RSet(Bin(liczba),8,"0"),9-numer))-'0'
But the first bit has to be inverted, so now I got it (hopefully;)...
Even when Helles code is the best solution for the given problem, I'll try to add one additional idea for optimizing similar problems, it may be useful (especially when slow math functions are involved) to create a result table at the beginning...
Code: Select all
Procedure OdbierzASM(liczba.b, numer) ;32-Bit
;value-range liczba: 0-255, value-range numer: 1-8
!MOVZX eax,byte[p.v_liczba]
!CMP dword[p.v_numer],8 ;if numer is long
!JNE @f
!SHR eax,7
!NOT eax
!AND eax,1
ProcedureReturn ;integer!
!@@:
!MOV cl,[p.v_numer]
!DEC cl
!SHR eax,cl
!AND eax,1
ProcedureReturn ;integer!
EndProcedure
Global Dim SBits.b(255,8)
For l = 0 To 255
s.s=RSet(Bin(l),8,"0")
PokeB(@s,'0'+'1'-PeekB(@s))
For i=1 To 8
SBits(l,i)=Asc(mid(s,9-i,1))-'0'
Next i
Next l
For liczba = 0 To 255
a.s=""
b.s=""
For numer = 1 To 8
a=Str(OdbierzASM(liczba, numer))+a
b=Str(Sbits(liczba,numer))+b
Next numer
If a<>b
Debug Str(liczba)+": "+a+"~"+b
EndIf
Next