1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Adding HEX bits in a byte.

Discussion in 'Mathematics and Physics' started by camerart, Apr 17, 2017.

  1. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,684
    Likes:
    827
    Location:
    Rochdale UK
    ONLINE
    You are missing the fact that some of these settings are bits 4~5 or 6~7
    Take my example

    PA = 128
    MaxPower = 64
    OutputPower = 7;

    PA is bit 7

    Maxpower is bits 4, 5 and 6
    Output power is bits 0, 1, 2 and 3

    So
    Const PA = 0x80
    Const MaxPower = 0x10 ( lowest ) thro to 0x70 ( highest )
    Const Output power = 0x00 ( lowest ) to 0x0f ( highest )

    Each bit ored together make up the final register
     
  2. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.
    Hi,
    A penny has just dropped! Unless each section 0x?? is set to it's correct bit number (As has been pointed out before), this ORing can't work.
    I'll re try in Oshonsoft with different numbering.
    C.
     
  3. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.
    Hi I
    Your comment came as my penny was dropping.
    I'll try a few of the suggestions in Oshonsoft, and see if they work.
    C.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.

    Hi,
    I've just tried this long hand method of setting the REGISTERS
    Const regopmode = 0x01
    Const w_regopmode = 0x01 or 0x80

    Dim lora_fsk_reserved_low_sleep As Byte
    lora_fsk_reserved_low_sleep = %10001000
    Dim lora_fsk_reserved_low_tx As Byte
    lora_fsk_reserved_low_tx = %10001011
    Dim lora_fsk_reserved_low_rx As Byte
    lora_fsk_reserved_low_rx = %10001101

    I think the answer to the original question I asked would take a better programmer than me. With the method above, I can visualise the bits better. I'll see how I get on as the list gets longer. It's possible that once I've understood the bit .number method, if it's easier may change later.
    Thanks to all for their input, much appreciated.
    C.
     
  6. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,702
    Likes:
    1,077
    remember
    Pseudocode
    To set a bit you OR: A= A .OR, value
    To clear a bit, you AND the inverse: A=A .AND. .NOT. value

    It's a lot easier to operate on unsigned integers.
     
  7. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.
    Hi K,
    I'm sure your answer will be easy to understand, for programmers practiced in operators, but for dunces like me, it will need to be spelled out, if you have the patience.

    KIS:)
    When I am practicing with operators, I use this method. I use a calculator and write the answer like this: %10000000 or %00000001 = %10000001
    I think that when DOTs are used this refers to a BIT, is this correct? So far I haven't tried changing bits on their own, but instead change the byte e,g, %00000011 to %00000010. I know this is the same, but it takes time for the 'penny to drop' and be remembered. I now know that unsigned means no negatives, and in what I am doing there aren't any.
    Thanks, C.
     
  8. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,702
    Likes:
    1,077
    Set

    Value to set (2^2) = 4 = 0000 0100
    Present value: 1010 1011

    1010 1011 initial value
    0000 0100 bit to set
    0000 0111 after .OR. operation

    Clear

    1010 1011 initial value
    0000 0100 bit to clear
    1111 1011 complement of bit to clear NOT (0000 0100)
    1010 1011 final value after ANDING, Note the bit is unchanged because it was clear already

    Another comment:
    1010 1011 converted to HEX = 10d 11d = ABh; You just group into 4 bits.
    and finally
    010 101 011 converted to Octal = 253o ; You just group into three's instead of 4 from the LSb

    Back in the day (mid 70's), octal was very common for me. My guess is we had to enter numbers from physical switches, thus Octal was easier.

    ==

    Unsigned means no negatives which is true. We generally use 2's complement notation, so there is only one zero in the set of numbers. Thus a 16 bit number has a range of -32768 (1111 1111) to 32767 (0111 1111). Many integer 2's complement 16 bit systems will make 32767+1 = -32768. I used that fact in high school to crash our time-shared computer. The crash dump told them it was our school, so they changed the password until someone, me, confessed. I wasn't supposed to tell anyone how I did it and not do it again.

    Sometimes you have to deal with magnitude and sign.
     
  9. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.
    Hi K,
    I'm sure your answer will be easy to understand, for programmers practiced in operators, but for dunces like me, it will need to be spelled out, if you have the patience.

    KIS:)
    When I am practicing with operators, I use this method. I use a calculator and write the answer like this: %10000000 or %00000001 = %10000001
    I think that when DOTs are used this refers to a BIT, is this correct? So far I haven't tried changing bits on their own, but instead change the byte e,g, %0000001 to %00000010. I know this is the same, but it takes time for the 'penny to drop' and be remembered. I now know that unsigned means no negatives, and in what I am doing there aren't any.
    Thanks, C.
    Hi k,
    This deserves a printout and a long stare. Much appreciated, thanks.
    Can I ask a bit more? How does MASK fit into this, please?
    C.
     
  10. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,702
    Likes:
    1,077
    A bit MASK effectively covers the bit your interested in.
    So if you had 0001 1001 and wanted to know if bit zero (2^0) is set, the MASK is: 0000 0001
    Thus the test is IF VALUE .AND. MASK = .TRUE. then the bit is set. If it's FALSE, then the bit is not set.

    My C is too rusty right now. The .AND. stuff is actually from the FORTRAN ERA. My first C program was an operating system with instruction set simulation done as a team of two. It was a crash course in C.

    Basically .FALSE. has a value of zero and .TRUE. generally has a value of -1, but anything non-zero tests as TRUE in some systems,

    The Boolean stuff and the integer stuff sometimes gets "mixed up". In C you have "typecasting"
     
  11. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.
    Hi K,
    I'll add this to my printout sheet. Your C is good enough for me.

    I learnt BASIC when my son got his first computer in the early 80s, I still struggle with BASIC, but because of all of the help I get from this forum and others, I keep enjoying this hobby. (Not to mention the headaches :) )
    Thanks, C.

     
  12. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,702
    Likes:
    1,077
    My first any programming project have been HUGE. Like my FIRST FORTRAN program took me and one other person 9 months to code nearly full time. LabVIEW is a data flow programming language which is the deFacto standard for controlling Instrumentation. http://store.digilentinc.com/labview-home-bundle/ It was very Bizzare learning when it was in it's infancy and was constantly changing. One problem is, instrument drivers are released by the manufacturer of the instrument on a particular version, so your constantly upgrading.

    I spent learning and managing a $100,000 USD upgrade project. I was a bit over extended, managing, doing hardware and software design and sometimes development.
    One program in this upgrade ran for 17 years with no changes and no hard drive crashes. The only computer issue was dust and a floppy drive replacement.

    When I did RCA COSMAC 1802 Assembly language programming, that processor used a "pass the program counter" method. Any register could be the program counter.
    One of the first routines I wrote was a subroutine call and return. The entire program to control a model train gantry crane was hand coded. I owned an Amiga computer at the time. See: https://en.wikipedia.org/wiki/RCA_1802
     
  13. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.
    Hi K,
    Are you saying that you designed LABVIEW? If so that is impressive. If I was starting again, I would have a closer look at it.
    My biggest project was a Photographic laboratory, all working from ZX Spectrums. I could process any film from 35mm to 1/2 plate, black/white colour and transparency. I was a photographer and what luxury to have it. I could then print 16inch by any length paper. Happy days:)
    C.


     
  14. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,702
    Likes:
    1,077
    No. I was designing a 4-terminal I-V converter as a front-end for a Lock-in amplifier all during the time I was managing software design using Labview. LabView wasn;t mature at the time, so I had to code "flicker-fixers" so that numbers would not flicker and all sorts of things. We used a program that could make keystrokes kit buttons, So, you have the Human Interface aspect. This was used for production test so you interacted with the program every 3 minutes.

    The initial design didn't work out. The laser printer took too long to warm-up, so printing of the results was done in a batch process. I wanted to do the testing in a different way, but it took 17 years to adopt. So, project management for a huge software/hardware project is a mess.

    I did very little of the actual programming, but all of the software design and I did write all of the routines that talked to instrumentation. Program design used a "simulate mode" so the instruments didn't have to be present, so that 3 minute cycle could be eliminated during development. The person doing the programming didn't know LabView either.

    ==

    The program I did as a team in the 80's was really cool. The IBM PC didn't exist at all. We had 7 PID loops, recipes etc. using a real-time OS. The hard drive the size of a suitcase and the company going under meant it had to be replaced. So, with much reduced functionality, 7 programmable temperature controller were used.
     
  15. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.
    Hi K,
    Still impressive, and not my cup of tea. I suppose things would have been different if I had chosen a different path.
    In the 70s, I had to help set-up dust monitoring in the London airport computer building, involving a sea of computers. The nearest I got to computing, was to look in one of the boxes and watch the lights flashing.
    C.
     
  16. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,684
    Likes:
    827
    Location:
    Rochdale UK
    ONLINE
    Making a comeback now..... I have just installed ZXbasic... I always used ASM on the old ZX but now this lets me do anything!!! Its based on freebasic and compiles to machine code so the speed is brilliant!!
     
  17. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,081
    Likes:
    8
    Location:
    Dorset UK.
    Hi I,
    I bought the Spectrum for my son for Christmas as inducement to do better at school. As you know there was no monitor with it, as it plugged into the Tv. So instead of watching Tv, I 'had' to watch 'A dot' arriving on the screen, then a circle etc. I would pick up the excellent manual which is written in a way, that I could follow. I learnt BASIC, by forced osmosis. We then got things to work from the rear socket of the spectrum, and I was hooked. Not forgetting MANIC MINOR.
    C.
     

Share This Page