Results 1 to 10 of 10

Thread: How to manipulate specific bits of a variable

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    if you want to stay delphi compatible, you can use and/or operators to do some bit operations. for example, $08 is equivalent to 0000 1000, then you can test ( somevar and $08 ) = $08 to check if 4th bit is set, if you want to check 7th bit you use $40, ( somevar and $40 ) = $40. there's a trick that worked for me, as you know, every bit is a power of 2, the first 8 bits are 1, 2, 4, 8, 16, 32, 64, 128, if you wrote them in hex, you get $01, $02, $04, $08, $10, $20, $40, $80, can you see the pattern? it stays the same if you work with more bits, just add a 0 at the end and you get 4 more bits or a nibble (half byte).
    Last edited by pitfiend; 14-07-2013 at 08:49 AM.

Bookmarks

Posting Permissions

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