Shop OBEX P1 Docs P2 Docs Learn Events
Convert binary pins to decimal? — Parallax Forums

Convert binary pins to decimal?

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2007-03-25 22:28 in Propeller 1
I'm creating a routine that look like this..
(I know the pins are goofy, but everything else is allocated.)

var =: ina[noparse][[/noparse]31,30,16,9,4,5,6,7]

I want to bring var in as a binary number, then convert it to a decimal variable.

Can someone show me how to do this?

My binary truth table for this is:
31=128
30=64
15=32
9=16
4=8
5=4
6=2
7=1

Thanks
Oldbit

Comments

  • cgraceycgracey Posts: 14,133
    edited 2007-03-25 02:53
    You could do this:

    'Arrange ina bits into x
    x~
    repeat i from 1 to 8
    x := x<<1 + ina[noparse][[/noparse]lookup(i : 31, 30, 15, 9, 4, 5, 6, 7)]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-25 02:53
    You're going to have to do this the "hard way" like:
    var := ((var >> 24) & $C0) | ((var >> 10) & $20) | ((var >> 5) & $10) | ((var >> 4) >< 4)
  • T ChapT Chap Posts: 4,223
    edited 2007-03-25 02:53
    Here is my best guess:


    var := ina[noparse][[/noparse] 31] << 7 + ina[noparse][[/noparse] 30] << 6 + ina[noparse][[/noparse] 16] << 5 + ina[noparse][[/noparse] 9] << 4 + ina[noparse][[/noparse] 4] << 3 + ina[noparse][[/noparse] 5] << 2 + ina[noparse][[/noparse] 6] << 1 + ina[noparse][[/noparse] 7]

    Even close anyone?
  • cgraceycgracey Posts: 14,133
    edited 2007-03-25 02:56
    Wow! This is very efficient because it exploits the pin·patterns. I'm sure it's fast, too. Graham's is the next fastest, and mine's the slowest.
    Mike Green said...
    You're going to have to do this the "hard way" like:
    var := ((var >> 24) & $C0) | ((var >> 10) & $20) | ((var >> 5) & $10) | ((var >> 4) >< 4)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-03-25 03:01
    You guys blow me away.. Thanks! I saw lines,lines,lines of code the way I was looking at it.

    BTW, Chip, see anything familiar in this pic? [noparse]:)[/noparse] [noparse]:)[/noparse]

    Oldbit
    408 x 308 - 28K
  • cgraceycgracey Posts: 14,133
    edited 2007-03-25 03:23
    Hey, an ISEPIC! I made that when I was sixteen and it took me a year. I remember laying out the PCB on my dad's drafting table using velum and various-width sticky black tapes. Everything was photographically reduced to 25% to make the PCB. If you look at that board, you'll see very analog-looking lines. That project was mainly software, so·the hardware's job was very simple -- just generate an NMI pulse and bank in our own 2KB SRAM at $FFFC and $FFFD for the interrupt vector, and provide a banked window to it at (I think) $C000. I didn't understand bus timing back then, so the SRAM access was marginal on writes for some machines. I tried to correct it in software by adopting some strict SRAM write policy. As I was rewriting that code, I stayed up for 5 days and nights working around the clock. I began on Thursday morning and went to bed on Tuesday night, breaking only to eat. My body won't do that anymore. Most days now end with me nodding off several times before I go to bed.
    Oldbitcollector said...
    You guys blow me away.. Thanks! I saw lines,lines,lines of code the way I was looking at it.

    BTW, Chip, see anything familiar in this pic? [noparse]:)[/noparse] [noparse]:)[/noparse]

    Oldbit

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • MacGeek117MacGeek117 Posts: 747
    edited 2007-03-25 22:28
    >>I stayed up for 5 days and nights working around the clock.

    After 1 day my brain would be shot!
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.startrek.com
    ·
Sign In or Register to comment.