Shop OBEX P1 Docs P2 Docs Learn Events
mirror a decimal variable to a binary value — Parallax Forums

mirror a decimal variable to a binary value

lfreezelfreeze Posts: 174
edited 2008-03-01 00:57 in Propeller 1
After a lot of trial and error, I can't solve this simple problem.
I have a program which produces variables that look like binary number. they range between· 00000000 and 11111111 and can be any combination of
ones and zeros. I want to mirror the decimal variable into a binary value.
Here are a few examples of what I am trying to accomplish

decimal variable= 10101010----binary number=%10101010

decimal variable= 10110110----binary number=%10110110

I looked at format.spin and numbers.spin, and they want to convert
the variable not mirror it. Can anyone suggest a solution to this problem?
Thanks in advance.
Larry

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-29 23:35
    Will this do what you want?
    binary := 0
    repeat 8
       binary := (binary << 1) + (decimal / 10000000)
       decimal := (decimal // 10000000) * 10
    
    
  • lfreezelfreeze Posts: 174
    edited 2008-02-29 23:40
    Thanks for the quick response. I will try it and let you know

    Larry
  • lfreezelfreeze Posts: 174
    edited 2008-03-01 00:57
    Mike,

    As usual your math is amazing. The solution worked perfectly. I will now
    spend some time with the manual, and try to understand how you did it.

    Larry
Sign In or Register to comment.