negative bits

Mark Smith mark at maseurope.net
Wed Apr 2 11:12:27 EDT 2008


Claus, you could do this:

on toBits tNum
    put binaryencode("n", tNum) into tBytes -- n is 4 bytes, if your  
numbers aren't going to be big, you could use 's' -- 2 bytes
    get binarydecode("B*", tBytes, tNum)
    return tNum
end toBits

Best,

Mark



On 2 Apr 2008, at 15:10, Claus Dreischer wrote:

> Hi,
>
> maybe someone has done this already ...
>
> I'd like to convert integers into binary ones and zeros like
> input: "9" -> output "1001" or depending on the size of the output:  
> "00001001"
>
> This can be done with the baseConvert function:
>    baseConvert( 9, 10, 2 ) gets me my "1001"
>
> BUT (and we finaly get to the point)
> converting a *negative* integer number won't get me the desired  
> result:
>    baseconvert( -9, 10, 2 )  -> "-1001"
>
> The anticipated result would be "11110111"
>
> So, how do i get there?
> Am i missing something?
>
> Regards,
>    Claus.
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list