Axis
Axis

Reputation: 846

Error codes OR'd together

I am having trouble figuring this one out and I could use some help. So the data sheet to some hardware says "The reported error code is the OR’d result of each detected error. Error codes are given in Table 3."

Table 3 is

0x00 -> No error
0x01 -> Power error
0x02 -> Receiver error
0x03 -> Transmitter error

The data sheet then shows an example.

Example :
(ETV001T0C) + checksum -> Test status 0x0C (Rx and Tx error)

0C is the error byte. So my first question is - Is my math wrong? I have no idea where they are getting 0C from. I am pretty sure that 0x02 | 0x03 = 0x03. And second even if it was 0C how do you figure out what errors are in that?

Upvotes: 0

Views: 116

Answers (1)

andrewdotn
andrewdotn

Reputation: 34833

The table is giving actually giving bit shift positions, as used by the << operator.

1 << 0x00 = 0001b (?) -> No error
1 << 0x01 = 0010b -> Power error
1 << 0x02 = 0100b -> Receiver error
1 << 0x03 = 1000b -> Transmitter error

Using python as a calculator:

>>> (1 << 2) | (1 << 3)
12
>>> hex((1 << 2) | (1 << 3))
'0xc'

Upvotes: 2

Related Questions