View previous topic :: View next topic |
Author |
Message |
laurencec
Joined: 01 Aug 2013 Posts: 1
|
Posted: Thu Aug 01, 2013 3:02 pm Post subject: Splitting an INTEGER or WORD into a byte array |
|
|
Hi all,
New to Bascom, just getting my head around the limited version. No problem with familiarity with micros and electronics though, we've got 15 years experience with HC11s, PICs, and AVRs using mainly ASM.
Bascom question: If I've got an int (never negative, i.e. 0 to 32767) or a word (0 to 65535) variable, bot can I split this into a 5 element byte array?
For example, given an int 21486, set MyByte(1) to 2, MyByte(2) to 1, MyByte(3) to 4, MyByte(4) to 8, MyByte(5) to 6.
2nd example, given a word int 47990, set MyByte(1) to 2, MyByte(2) to 7, MyByte(3) to 9, MyByte(4) to 8, MyByte(5) to 0.
Easy or impossible?
The rest of the console figured out, but this one hats us stumped.
Cheers
(BASCOM-AVR version : 2.0.7.6 ) |
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Thu Aug 01, 2013 3:07 pm Post subject: |
|
|
dim my_str as string * 5
dim my_byte_array(5) as byte at my_str overlay
dim str_len as byte, x as byte
my_str = str(my_word)
str_len = length(my_str)
for x = str_len to 1 step -1
print mid(my_str,x,1)
next
or
print my_byte_array(5) _________________ For technical reasons, the signature is on the back of this message. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Aug 01, 2013 7:33 pm Post subject: |
|
|
have a look at STR2DIGITS _________________ Mark |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|