Hi forum. I am using in my project the DAC8734 from TI driven by an Arduino Uno via SPI interface. It has two output voltage modes capability: unipolar and bipolar. unipolar from 0 to 20V and bipolar from -10V to +10 V. writing a 16bit value (from 0x000 (0) to 0xFFFF (65535)) to the DAC it can excurse in unipolar the whole voltage range from 0 to 20V.
for the bipolar it uses two-complementary code: from 0x000 to 0x7FFF outputs from 0V to 10V and from 0x8000 to 0XFFFF from -10V up to 0V. Note that +10V and -10V Values differ only from one single bit (more on this later)
Now I need to code following: I want a 2.7 V output. Which hex bit should I feed into the DAC? Now I want -5V, what is the linear formula?
I attach a screenshot of the datasheet. Assuming Vref is 5V and the Gain is set to x4 here is the formula:

Since I need to use float due to the division, how can I assure that I want for example maximum 10V (that would be setting 0x7FFF) and I am sure not to land a bit further away obtaining so -10V (0x8000)?

Those are equivalent to signed 16 bit integers in the range -32768 to 32767, except that there may be two different representations for 0V (ones complement). There is no need to be concerned about hex representation.

Please post a link to the data sheet.

All you really need to do is send the DAC -32768 for -10 V, 0 for 0V, 32767 for +10V and so on.

Avoid floating point calculations. To set output at 2.7V send to the DAC:

Thanks a lot for your quick reply. Here the link: https://www.ti.com/lit/gpn/dac8734.
You are correct. My fault. There is only one zero and it is 0x0000. The "negative" zero 0xFFFF is just in reality -LSB.
So as you say if I want -2.7V should I write int16_t negval = 27L * 32768/10;? or maybe
int16_t negval = -27L * 32768/10;?
By the way does a multiplication between a long and int value be allowed to fit into another signed int?
How is the overflow treated?
Time to do some C refreshing for me I suppose....
Best regards

The "L" forces the entire right hand side calculation to be done as long integers, but the result will always fit into 16 bits. It works for both signs. I doubt you could measure the difference between the two voltage outputs corresponding to -32768 and -32767.

For more decimal digits of accuracy (or if starting with a float value) multiply by a larger power of ten, for example, 1000:

float x = -2.735;
long temp = x*1000;
int16_t val = (temp*32767)/10000; //output on scale of 0-10.