NewDBitArrayFromInt creates a bit array from the specified integer at the specified width. If the width is zero, only positive integers can be converted. If the width is nonzero, the value is truncated to that width. Negative values are encoded using two's complement.
(i int64, width uint)
| 505 | // If the width is nonzero, the value is truncated to that width. |
| 506 | // Negative values are encoded using two's complement. |
| 507 | func NewDBitArrayFromInt(i int64, width uint) (*DBitArray, error) { |
| 508 | if width == 0 && i < 0 { |
| 509 | return nil, errCannotCastNegativeIntToBitArray |
| 510 | } |
| 511 | return &DBitArray{ |
| 512 | BitArray: bitarray.MakeBitArrayFromInt64(width, i, 64), |
| 513 | }, nil |
| 514 | } |
| 515 | |
| 516 | // AsDInt computes the integer value of the given bit array. |
| 517 | // The value is assumed to be encoded using two's complement. |
no test coverage detected
searching dependent graphs…