negative bits

Claus Dreischer claus at dreischer.de
Wed Apr 2 11:59:06 EDT 2008


Hi Mark,

thank you very much, this does the trick!

For reference, i expanded Marks's function to use tLength <= 32 bits:


function toBits tNum, tLength
    put binaryencode( "N", tNum ) into tBytes
    get binarydecode( "B*", tBytes, tBits )
    
    repeat with i = 1 to tLength 
        put char -i of tBits before my_bits
    end repeat
    
    return my_bits
end toBits


Again, thanks Mark for the fast response!

Regards,
   Claus.


----- original Nachricht --------

Betreff: Re: negative bits
Gesendet: Mi, 02. Apr 2008
Von: Mark Smith<mark at maseurope.net>

> 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
> 
> _______________________________________________
> 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
> 

--- original Nachricht Ende ----




More information about the use-livecode mailing list