combining variables

centrex

Senior Member
I have a need to combine two 8bit variables into a word variable.

Say one variable has a value of 30 and another has a value of 2 how can I put these into a word variable that reads 302.
Reading a temperature and then making into a word for logging and later manipulating in Excel.
regards
Centrex
 

Dippy

Moderator
Just to clarify: you want to put 2 bytes together as described ? As opposed to making a MSB&LSB into a word?
They are two different animals.

If you want to do as you have described in your example, whats wrong with simple multiplication and additon.
eg.
Code:
symbol BigN=b0
symbol SmallN =b1
symbol Result = w1	' Resultant Word variable

BigN=30
SmallN=2

Result = BigN*10+SmallN
As long as you rmember the limitaions of byte and word variable size.
Have I missed something?

If, however, you just want to make a word sized variable from 2bytes then its even easier.
 

Mycroft2152

Senior Member
30 + 2 = 302?

Sounds like two binary coded decimal bytes.

30 x 10 = high byte
2 = low byte

Use the b0,b1 trick, then multiply b1 by 10

Myc
 

centrex

Senior Member
Thank you all.
I think Dippy's answer is what I want I will give it a try.
Lot easier using Excel to play with the mathamatics.
 
Top