I'm confused about the bottom statement from this API's documentation. The API is meant to control an FPGA using Python commands. From the first line I can conclude that the 0x07 is the address of the input wire, but how does bit 3 get written with a value of 1 in the bottom command?
Converting 04 from hex to decimal gives: (0*16^1 + 4*16^0 = 4)
which only adds to my confusion.
Here is the link.
This is a common way to handle single bits in a register. You need to think how the numbers are represented in binary (don't try to convert it to decimal as it won't help).
Hardware registers use single bits (or group of bits) for enabling/disabling features, so it's really common to wanting to write a particular bit by first selecting the register with its address and then writing the bits you are interested in.
The easiest way to write single bits is to write the number in binary, so say that I need to set only the first and the fourth I would write 0b1001
. In order to keep things more concise usually people write the hex equivalent, which in this example is 0x9.
In your example 0x4 = 0b100
so you are writing to the third bit.
If you don't want to overwrite the entire word you can use a mask as well which changes only the bits selected by the mask or you can do it manually by reading first the value of the register and then using these operations:
// Turn on only the n-th bit
reg = reg OR (1<<n)
// Turn off only the n-th bit
reg = reg AND ~(1<<n)
If you want to learn more you can look at bitwise operations and any microcontroller manual.