Shop OBEX P1 Docs P2 Docs Learn Events
Concatenate variables — Parallax Forums

Concatenate variables

flowakfgflowakfg Posts: 2
edited 2011-11-30 12:05 in BASIC Stamp
Hello, I am new to PBASIC and would like to know how to Concatenate a word variable. For example, the word could store 3000. I want it to change to 30. How would I do this?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2011-11-30 10:27
    Not sure what you really want but in your example just devide by 100.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-30 11:21
    Concatenate is a term usually used for strings of characters, not numbers. A word can hold any signed number from -32768 to 32767 or an unsigned (positive) number from 0 to 65535. The Stamps normally do arithmetic on unsigned word values, but you can work with signed 2's complement arithmetic if you're careful. A byte can hold an unsigned number from 0 to 255.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-11-30 11:45
    Also, concatenate means to link or join together, but in your example you are removing characters.
  • flowakfgflowakfg Posts: 2
    edited 2011-11-30 11:54
    Sorry, you are right, I used the wrong term. I meant to remove. It want to only get the first two digits stored in a variable instead of four. Dividing by 100 would not help because in my case the variable's one's place is fluctuating its value from a sensor. It would be nice if I could make it a fixed number especially becuase I want to do further manipulation on it. Is there any way to do this?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-30 12:05
    Dividing by 100 would do it since division is integer arithmetic. Any remainder is discarded, so 3045 / 100 would be 30. If you want to round up, you'd do (3045 + 50) / 100.
Sign In or Register to comment.