-
C to TB question
I was converting some C code and hoping I was converting the following code correctly can someone confirm.
[code=CPP]{
int n;
for( n = 32; !(x & 0x80000000) && (n > 0); -- n ) x <<= 1;
return n;
}[/code]
[code=thinbasic]Local n As Integer Value N = 32
While Not ( ANDB(x, &h80000000)) And (n > 0)
Decr n
SHIFT LEFT x,1
Wend
Function = N[/code]
Thanks
Mike
-
Re: C to TB question
Hi Michael,
I usually translate 0xNNN... hexanumbers like &h0NNN..., that makes them unsigned. But in this case it does not seem to do difference.
But I think your code works, except the first line, where your duplication of N makes trouble.
I would write it as:
[code=thinbasic]
Local n As Integer = 32
While Not ( ANDB(x, &h080000000)) And (n > 0)
Decr n
SHIFT LEFT x,1
Wend
Return N
[/code]
... as ThinBasic has return as well.
Petr
-
Re: C to TB question
I missed the duplication of N (it was late lastnight)
Thanks Petr