toSMBigEndian function

List<int> toSMBigEndian(
  1. BigInt value
)

Implementation

List<int> toSMBigEndian(BigInt value) {
  List<int> buf = [];
  if (value.compareTo(BigInt.zero) == -1) {
    buf = toBuffer(-value);
    if (buf[0] & 0x80 != 0) {
      buf = [0x80] + buf;
    } else {
      buf[0] = buf[0] | 0x80;
    }
  } else {
    buf = toBuffer(value);
    if (buf[0] & 0x80 != 0) {
      buf = [0x00] + buf;
    }
  }

  if (buf.length == 1 && buf[0] == 0) {
    buf = [];
  }
  return buf;
}