Bits, Bytes Words and Arrays


+ Reply to Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    6. How can I reference a WORD in a BYTE ARRAY?

    Let's say that you have a WORD located at bytes 3 and 4 of a BYTE array, and Byte 3 is the LowByte. You can use the EXT (external) modifier to assign it to a WORD variable.


    MyByteArray VAR BYTE[10]

    MyWord VAR WORD EXT
    @MyWord = _MyByteArray + 3

    DT

  2. #2
    Join Date
    Dec 2004
    Location
    USA
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,

    Your example will put the low byte into the array. How do I get the high byte in?

    MyByteArray VAR BYTE[10]
    MyWord.byte0 VAR MyByteArray[3]

    or

    MyByteArray VAR BYTE[10]
    MyWord.byte1 VAR MyByteArray[3]

    will work as well.

    I can read in either the high or low byte, but not both of them.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It creates an Aliased WORD variable, inside the BYTE array.

    When you assign a value to the WORD variable, it puts both BYTEs in the array in a single operation.

    MyWord = $1234

    will make MyByteArray look like this

    [00, 00, 00, 34, 12, 00, 00, 00, 00, 00]

    HTH
    DT

  4. #4
    Join Date
    Dec 2004
    Location
    USA
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Thanks again Darrel. That's almost too slick to be true. When you start throwing around those "@" signs it becomes a little mystical for me.

    I will try it and let you know.

  5. #5
    Join Date
    Jun 2006
    Location
    Bangalore, India
    Posts
    136


    Did you find this post helpful? Yes | No

    Thumbs up Thank You

    After searching the whole forum for an hour or so i stumbled upon this page.
    Finally i can dynamically access bits of a variable. This has really helped me a lot.
    Thank you Melanie .

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Isn't this information in the PicBasic Pro Compiler doc's... something like "Variables", "Aliases", "Arrays" and so forth...?

    Mike Tripoli

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mtripoli View Post
    Isn't this information in the PicBasic Pro Compiler doc's... something like "Variables", "Aliases", "Arrays" and so forth...?

    Mike Tripoli
    Probably most of it, Manuals and Data sheets are written by engineers, FOR engineers, and some of us NON engineers have a little trouble getting our heads around them, SO an experienced Advisor / Professor / Engineer / Guru / or even Lay person who knows, lending guidance is appreciated, and welcomed even if some of see it as too basic. You are new here, Welcome, Your statement tells me you might be really knowledgeable. I hope so, we can always use more people who are. I am not, but I help when I can. I learn something here nearly every time I come in. Every newbie can figure out a different way to "stall out" and I have seen some pretty unusual new ideas (that often do not work ) but they challenge me to think, and learn.
    Again Welcome Mike Tripoli.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. LP Instant Interrupts Error
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th December 2009, 10:13
  2. how to store a very large amount of data
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 2nd April 2008, 07:05

Members who have read this thread : 4

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts