Shop OBEX P1 Docs P2 Docs Learn Events
Subtracting contents of a BYTE — Parallax Forums

Subtracting contents of a BYTE

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2007-11-12 06:20 in Propeller 1
How do I subtract a number from a byte variable?

I've got some code that is case sensitive, so I need to decrease the contents of the byte by 32
to change case. Is there an easy way to do this instead of a lookup table?


Example if "@byte:=97" I need it to equal 65 (lower to upper)

Thanks
OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.

— Calvin, of 'Calvin and Hobbes.

Comments

  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-11-12 05:59
    I'm not sure what you mean by @byte:=97. That's not valid spin.

    But to subtract from a byte variable "b" use b-=32

    If you have a pointer to a byte "p", use byte[noparse][[/noparse]p]-=32

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Help to build the Propeller wiki - propeller.wikispaces.com
    Prop Room Robotics - my web store for Roomba spare parts in the UK
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-12 06:04
    Try this:

    if (ch => "a" AND ch =< "z") 
      ch -= 32
    
    
    



    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-12 06:05
    You subtract a number from a byte variable just like you'd do it with any
    other variable: "variable := variable - 32" or "variable -= 32".
    If what you have is an address, you'd use "byte[noparse][[/noparse] <address> ] -= 32".

    You could do: "variable := ((variable > $5F) & $20) ^ variable".
    It always converts lower case characters (anything from $60 to $7F)
    to upper case characters (from $40 to $5F).
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-11-12 06:20
    I was stuck; missing the = sign.

    Working perfectly -- Thanks!

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.

    — Calvin, of 'Calvin and Hobbes.
Sign In or Register to comment.