Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. QtonPi
  4. to write in bits of register
QtWS25 Last Chance

to write in bits of register

Scheduled Pinned Locked Moved Unsolved QtonPi
9 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    carter_james
    wrote on last edited by
    #1

    hello people how may i write on a 32 bit register the value
    int a=2 in the bit 19 until 31 (31,30,29,28,27,26,25,24,23,22,21,20,19).

    kshegunovK 1 Reply Last reply
    0
    • yeckelY Offline
      yeckelY Offline
      yeckel
      wrote on last edited by
      #2

      What about:
      set the bit:
      a |= 1 << x; //where x is the bit?

      reset the bit:
      a &= ~(1 << x);

      toggle:
      a ^= 1 << x;

      1 Reply Last reply
      0
      • C carter_james

        hello people how may i write on a 32 bit register the value
        int a=2 in the bit 19 until 31 (31,30,29,28,27,26,25,24,23,22,21,20,19).

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        @carter_james

        int bitmask = 0x7FFC0000
        

        on a 32 bit register

        Do you mean a CPU register?

        Read and abide by the Qt Code of Conduct

        C 1 Reply Last reply
        0
        • kshegunovK kshegunov

          @carter_james

          int bitmask = 0x7FFC0000
          

          on a 32 bit register

          Do you mean a CPU register?

          C Offline
          C Offline
          carter_james
          wrote on last edited by
          #4

          @ kshegunov no CPU register only data register what may i have to do with the bitmaske?

          kshegunovK 1 Reply Last reply
          0
          • C carter_james

            @ kshegunov no CPU register only data register what may i have to do with the bitmaske?

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @carter_james
            You can use it to mask the number:

            int number = 2;
            int a = ((number << 19) & 0x7FFC0000);
            

            Read and abide by the Qt Code of Conduct

            C 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @carter_james
              You can use it to mask the number:

              int number = 2;
              int a = ((number << 19) & 0x7FFC0000);
              
              C Offline
              C Offline
              carter_james
              wrote on last edited by
              #6

              @kshegunov i get trouble with that.because the value of number changed.
              i want that the value d ont change

              kshegunovK 1 Reply Last reply
              0
              • C carter_james

                @kshegunov i get trouble with that.because the value of number changed.
                i want that the value d ont change

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @carter_james
                I'm sorry I don't understand, what value is changing and why?

                Read and abide by the Qt Code of Conduct

                C 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  @carter_james
                  I'm sorry I don't understand, what value is changing and why?

                  C Offline
                  C Offline
                  carter_james
                  wrote on last edited by carter_james
                  #8

                  @kshegunov kshegunov the fact ist: i want to send server data to a receiver. for example
                  we have server data like:
                  int a=2;
                  int b=3;
                  int c=0;

                  this three value have to be send to receiver , bevor that they have to be write on a 32bit Register with
                  certain position.for example value a between bit 19 and 32, value b between bit 0 and 4, value c between bit 7 and 9.
                  this value after be written in register,they have to be send(3 bytes) to receiver,because of that the value dont have to be change.
                  after shift operation i search a possibility to get the original value

                  kshegunovK 1 Reply Last reply
                  0
                  • C carter_james

                    @kshegunov kshegunov the fact ist: i want to send server data to a receiver. for example
                    we have server data like:
                    int a=2;
                    int b=3;
                    int c=0;

                    this three value have to be send to receiver , bevor that they have to be write on a 32bit Register with
                    certain position.for example value a between bit 19 and 32, value b between bit 0 and 4, value c between bit 7 and 9.
                    this value after be written in register,they have to be send(3 bytes) to receiver,because of that the value dont have to be change.
                    after shift operation i search a possibility to get the original value

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #9

                    @carter_james
                    So what's stopping you from masking the relevant bits and shift them accordingly?

                    int a = 2;
                    int b = 3;
                    int c = 0;
                    
                    int data = (b & 0x1F) | ((c & 0x7) << 7) | ((a & 0x1FFF) << 19); //< This would be the "register" you want.
                    

                    Also an integer is the size of 4 bytes (32 bits), not 3.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved