Menu

FAQ#1: Using Great Cow Basic Variables

Help
Anobium
2013-11-07
2017-09-16
  • Anobium

    Anobium - 2013-11-07

    In Great Cow Basic you have byte variables, word variables, long variables and integer variables. See http://gcbasic.sourceforge.net/help/_setting_variables.html for the help file.

    Accessing bytes within words and longs etc may be required when you are creating your solution. This can be done with some ease.

    You can access the bytes within word and longs variables using the following as a guide:

     Dim workvariable as long
        workvariable = 21845
        Dim lowb as byte
        Dim highb as byte
        Dim upperb as byte
        Dim lastb as byte
    
        lowb      = workvariable
        highb     = workvariable_H
        upperb    = workvariable_U
        lastb     = workvariable_E
    

    Just to confirm, where

        Dim rB as Byte
        Dim sW as Word
        Dim sW as Word
    

    To extract the bytes from a WORD of 16 bits

         For bits 7-0 [lower byte]
        rB = sW
    
         For bits 15-8 [upper byte]
        rB = sW_H
    

    To extract the bytes from a LONG of 32 bits, where

        Dim rB as Byte
        Dim sW as Word
        Dim tL as Long
    
        ‘ For bits 7-0 [lowest byte #0]
        rB = tL
    
        ‘ For bits 15-8 [lower middle byte #1]
        rB = tL_H
    
        ‘ For bits 23-16 [upper middle byte #2]
        rB = tL_U
    
        ‘ For bits 31-24 [highest byte #3]
        rB = tL_E
    ~~~~
    
    To extract nibbles from variables  
    
    lower_nibble = rB & 0x0F 
    upper_nibble = (rB & 0xF0) / 16
    

    ~~~~~

    This FAQ was first created by Perry (OFUZZY1), Thank You!!

     

    Last edit: Anobium 2017-09-16
  • Paul Haug

    Paul Haug - 2017-09-10

    Thanks Anobium , good info. I have printed and put in my notes of GCB.
    Paul

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.