"Stretching" a byte variable into two byte variables?


Results 1 to 10 of 10

Threaded View

  1. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: "Stretching" a byte variable into two byte variables?

    Code:
        any_byte=101011  ;eg input any_byte-> 10101011
        for any_cnt=0 to 7
        any_word=any_word<<2
        if  any_byte.7 then any_word=any_word+3
        any_byte=any_byte<<1
        next
    output any_word-> 1100110011001111


    mikes
    Code:
    X VAR WORD
    Y VAR WORD
    ;eg input any_byte-> 10101011
    
    
    X = ani_r
    Y = ani_r << 4
    X = X ^ Y
    X = X & $0F0F
    Y = X << 2
    X = X ^ Y
    X = X & $3333
    Y = X << 1
    X = X ^ Y
    X = X & $5555
    ani_h = X << 1
    output any_word-> 1000100010001010


    not working



    corrected

    Code:
    x = ani_r;
    x = (x ^ (x << 4)) & $0f0f;
    x = (x ^ (x << 2)) & $3333;
    x = (x ^ (x << 1)) & $5555;
    ani_h = x | (x << 1);

    and works , probably quicker the my loop
    Last edited by richard; - 25th October 2021 at 00:30.
    Warning I'm not a teacher

Similar Threads

  1. "Variable already an alias" - is there a way to avoid this?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 18th June 2022, 23:22
  2. Byte from variable
    By Lilleljung in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th February 2015, 23:29
  3. Replies: 0
    Last Post: - 14th November 2013, 04:32
  4. Replies: 3
    Last Post: - 15th October 2012, 09:06
  5. AN Question for "word" variable read The serial port
    By redfoen in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2007, 18:39

Members who have read this thread : 0

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