---
name: "weighted_sum"
section: "9"
platform: "linux"
package: "linuxcnc-uspace"
version: "1:2.9.4-2+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/weighted_sum"
---

# weighted\_sum(9)

convert a group of bits to an integer

## NAME

weighted\_sum - convert a group of bits to an integer

## SYNOPSIS

**loadrt weighted\_sum wsum\_sizes=*size\[,size,...\]***

Creates weighted sum groups each with the given number of input bits (*size*).

## DESCRIPTION

The weighted\_sum converts a group of bits to an integer. The conversion is  the sum of the weights of the bits that are on plus any offset. The weight  of the m-th bit is 2^m. This is similar to a binary coded decimal but with  more options. The hold bit stops processing the input changes so the sum will  not change.

The default value for each weight is 2^m where m is the bit number. This  results in a binary to unsigned conversion.

There is a limit of 8 weighted summers and each may have up to 16 input bits.

## FUNCTIONS

- **process\_wsums (requires a floating point thread)**

  Read all input values and update all output values.

## PINS

- **wsum.*N*.bit.*M*.in bit in**

  The *m*'th input of weighted summer *n*.

- **wsum.*N*.hold bit in**

  When TRUE, the *sum* output does not change.  When FALSE, the *sum* output tracks the *bit* inputs according to the weights and offset.

- **wsum.*N*.sum signed out**

  The output of the weighted summer

- **wsum.*N*.bit.*M*.weight signed rw**

  The weight of the *m*'th input of weighted summer *n*. The default value is 2^*m*.

- **wsum.*N*.offset signed rw**

  The offset is added to the weights corresponding to all TRUE inputs to give the final sum.

## SEE ALSO

[**scaled\_s32\_sums**(9)](/scaled_s32_sums/9.md), [**sum2**(9)](/sum2/9.md).
