For ubytes in freebasic doing it like this seems to work
imask1[i] = ( - idata1[i] ) >> 8;
but I get the feeling that's not guaranteed to work in C#
I can't think of a way with ubytes atm other than a bit of assembly (this is in FB)
sub main
dim as ubyte idata1(0 to 32767),imask1(0 to 32767)
for i as integer=1 to 20
idata1(i)=rnd*2'255
asm
mov ebx,dword ptr[i] 'load index
cmp byte ptr[idata1+ebx],0 'compare byte in array with 0
setz al 'if byte=0 then al=1 else al=0
dec al 'if al=1 then al=0 else al=255
mov byte ptr[imask1+ebx],al 'store byte to (imask1 array)
end asm
print idata1(i);" ";imask1(i)
next
end sub
main
sleep