# How to set default value for yang leaf type "bits"

**URL:** <https://dmap-community.ductus.global/t/how-to-set-default-value-for-yang-leaf-type-bits/3125>\
**Category:** YANG\
**Created:** [June 22, 2020, 9:40am UTC](https://dmap-community.ductus.global/t/how-to-set-default-value-for-yang-leaf-type-bits/3125 "2020-06-22T09:40:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kboyapa1](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kboyapa1](https://dmap-community.ductus.global/u/kboyapa1)\
**Post date:** [June 22, 2020, 9:40am UTC](https://dmap-community.ductus.global/t/how-to-set-default-value-for-yang-leaf-type-bits/3125/1 "2020-06-22T09:40:47Z")

</div>

I am defining a yang leaf “tlvmap” of type “bits” which has multiple bit positions defined. I want to add a default value (130943) for this leaf. When I added “default” statement to add the value as shown below, the confdc compiler is giving error like “ **error: the value “130943” is not valid for the base type - bit not defined for bits type defined** ”. Can please suggest, how to set default value for yang leaf type bits?

```
leaf tlvmap {
    type bits {
        bit chassis-id {
            position 0;
        }

        bit port-id {
            position 1;
        }

        bit ttl {
            position 2;
        }

        bit port-description {
            position 3;
        }

        bit system-name {
            position 4;
        }

        bit system-description {
            position 5;
        }

        bit system-capabilities {
            position 6;
        }

        bit management-address {
            position 7;
        }

        bit pvid {
            position 8;
        }

        bit ppvid {
            position 9;
        }

        bit vlan-name {
            position 10;
        }

        bit protocol-identity {
            position 11;
        }

        bit macphy {
            position 12;
        }

        bit link-aggregation {
            position 13;
        }

        bit power-mdi {
            position 14;
        }

        bit mfs {
            position 15;
        }

        bit product-model {
            position 16;
        }
    }

    default 130943;
}
```

---

<div class="post-metadata">

**Author:** ![per](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@per](https://dmap-community.ductus.global/u/per)\
**Post date:** [June 22, 2020, 12:56pm UTC](https://dmap-community.ductus.global/t/how-to-set-default-value-for-yang-leaf-type-bits/3125/2 "2020-06-22T12:56:51Z")

</div>

From [https://tools.ietf.org/html/rfc7950#section-9.7.2](https://tools.ietf.org/html/rfc7950#section-9.7.2)

```auto
  The lexical representation of the bits type is a space-separated list
  of the names of the bits that are set. A zero-length string thus
  represents a value where no bits are set.

```

You need to use “the lexical representation” when specifying default values (for any type) - the use of a bitmask with the bit positions set (at least when it fits into 64 bits) is ConfD’s internal representation.

---

<div class="post-metadata">

**Author:** ![kboyapa1](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kboyapa1](https://dmap-community.ductus.global/u/kboyapa1)\
**Post date:** [June 23, 2020, 3:26am UTC](https://dmap-community.ductus.global/t/how-to-set-default-value-for-yang-leaf-type-bits/3125/3 "2020-06-23T03:26:32Z")

</div>

Thanks for your suggestion. This works for me.
