Difference between revisions of "Bit Masks"

From PREX Wiki
Jump to: navigation, search
(Created page with "{| cellpadding=5 style="margin:7px 30px 0 30px; <!-- --> float:right; border:1px solid #AA6633" |- bgcolor="#fbfeff" |Documentation |- | HOW TOs | HOW TOs for shift c...")
 
m (Japan Error Code Bit Masks)
 
(2 intermediate revisions by 2 users not shown)
Line 87: Line 87:
 
** Mask off just the last bit
 
** Mask off just the last bit
 
*** a = b & ~0x1
 
*** a = b & ~0x1
 +
 +
=== Japan Error Code Bit Masks ===
 +
* [https://github.com/JeffersonLab/japan/blob/operations/Analysis/include/QwTypes.h#L165 Header File in JAPAN that defines the Event Cuts and Error Code Bits]
 +
* [https://logbooks.jlab.org/entry/3701050 Note on using the stability cut in JAPAN parameter maps]
 +
* [https://logbooks.jlab.org/entry/3700923 Weibin's note on using the beam stability cut in JAPAN]
 +
* The event cuts are defined in _eventcuts.***.map files

Latest revision as of 12:22, 21 August 2019

Documentation
HOW TOs for shift crew
TaskList for 2019
Installation Photo Album
Run Plan
All Expert Contacts


PREX Main<< HOW TOs

Bit-wise operations

  • A 16 bit hexadecimal integer looks like
    • n = (digits) 0x4th 3rd 2nd 1st = n_16 n_15 n_14 n_13 | n_12 n_11 n_10 n_9 | n_8 n_7 n_6 n_5 | n_4 n_3 n_2 n_1
  • And the number 0x0177 is arrived at by
    • n = 0x0177 = 0000|0001|0111|0111

Hexadecimal numbering system

Hex Digit Decimal binary hex components binary binary hex components powers Decimal
0 0 0000 0 0^3 + 0^2 + 0^1 + 0^0 0
1 1 0001 1 0^3 + 0^2 + 0^1 + 2^0 1
2 2 0010 10 0^3 + 0^2 + 2^1 + 0^0 2
3 3 0011 11 0^3 + 0^2 + 2^1 + 2^0 3
4 4 0100 100 0^3 + 2^2 + 0^1 + 0^0 4
5 5 0101 101 0^3 + 2^2 + 0^1 + 2^0 5
6 6 0110 110 0^3 + 2^2 + 2^1 + 0^0 6
7 7 0111 111 0^3 + 2^2 + 2^1 + 2^0 7
8 8 1000 1000 2^3 + 0^2 + 0^1 + 0^0 8
9 9 1001 1001 2^3 + 0^2 + 0^1 + 2^0 9
a 10 1010 1010 2^3 + 0^2 + 2^1 + 0^0 10
b 11 1011 1011 2^3 + 0^2 + 2^1 + 2^0 11
c 12 1100 1100 2^3 + 2^2 + 0^1 + 0^0 12
d 13 1101 1101 2^3 + 2^2 + 0^1 + 2^0 13
e 14 1110 1110 2^3 + 2^2 + 2^1 + 0^0 14
f 15 1111 1111 2^3 + 2^2 + 2^1 + 2^0 15

Bitwise Operators

  • Logical And (&) -> a = b & c
    • Takes the bitwise (0's and 1's) representation of b and c and the result of each bit's & is "a"
  • Logical Inclusive Or (|) -> a = b | c
    • Takes the bitwise representation, and if either is 1 then a's corresponding bit is 1
  • Logical Exclusive Or (^) -> a = b^c
    • Takes the bitwise representation, and if just one of b or c's bits is 1 then a's corresponding bit is too, but if both are == then the result is 0
  • Logical Not (~) -> a = ~b
    • Takes each bit and returns its complement
  • Bit shift (>> or <<) -> a = b>>N
    • Takes the bit contents of b and shifts them N places to the right to produce a
  • Examples
    • Grab the 3rd digit of a hexadecimal integer and make that a new variable -> mask the other digits and shift the result to the right by 2
      • a = (b & 0x0f00)>>2
    • Mask off the top 8 bits (8th and 7th digit) of a 32 bit integer
      • a = b & 0x00ffffff
    • Mask off all but the last bit
      • a = b & 0x1
    • Mask off just the last bit
      • a = b & ~0x1

Japan Error Code Bit Masks