A few things not working properly. And flicker.


Author
Message
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 98K

Since I wasn't aware of a way to send integer
values to a port, [...]


What the hell, we might just come up with a way for the fun of it:


How to convert the answer to life, the universe and everything to 8 bit binary?


*********************************************
* Start Function: Convert Decimal to Binary *
*********************************************


<values>
/ dec = 42
/ bit = 0
/ nbits = 8
/ binarystring = ""
/ loopcount = 0
</values>

<expressions>
/ dec2bin = if(values.dec>=0 && values.loopcount<values.nbits)
    {
    values.loopcount=values.loopcount+1;
    values.bit=values.dec-(2*(ipart(values.dec/2)));
    values.binarystring=concat(values.bit,values.binarystring);
    values.dec=ipart(values.dec/2);
    expressions.dec2bin;
    }
</expressions>

<text mybinarystring>
/ items = ("<%values.binarystring%>")
</text>

<trial mytrial>
/ ontrialbegin = [values.binarystring=""; values.loopcount=0; expressions.dec2bin]
/ stimulusframes = [1=mybinarystring]
/ validresponse = (anyresponse)
</trial>


*******************************************

* End Function: Convert Decimal to Binary *

*******************************************



It's a bit bulky, I know. But hey, it get's the job done... And since I can't let this slide, here's some code for the reverse conversion:


*********************************************
*
Start Function: Convert Binary to Decimal *
*********************************************


<values>
/ dec = 0
/ bit = 0
/ binarystring = "00101010"
/ pos = 0
</values>

<expressions>
/ bin2dec = if(values.pos<length(values.binarystring))
    {
    values.bit=substring(values.binarystring,values.pos,1);
    values.dec=values.dec*2+values.bit;
    values.pos=values.pos+1;
    expressions.bin2dec;
    }
</expressions>

<text mydecimal>
/ items = ("<%values.dec%>")
</text>

<trial mytrial>
/ ontrialbegin = [values.dec=0; values.pos=0; expressions.bin2dec]
/ stimulusframes = [1=mydecimal]
/ validresponse = (anyresponse)
</trial>


*******************************************

* End Function: Convert Binary to Decimal *

*******************************************


Cheers,


~Dave


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search