Macchiato
Macchiato

Reputation: 541

Convert a Hexadecimal to Binary values

How to convert a Hexadecimal to Binary values.

Here is my code:

String authSign() {
    if (CheckDate % 2 == 0) {
      return Signature = H + B + Sk;
    } else {
      return Signature = B + H + Sk;
    }
  }

  ;

  var key = utf8.encode(authSign());
  var stringSha = sha256.convert(key);
  var stringHex = hex.decode(stringSha.toString());
  var finalHex  = hex.encode(stringHex.toList());

and here is the result:

flutter: dad85aac19b632a71b4759078bf90cbe4fba354582454f0445bc3bb8e3e4c587

and the result I want is:

64616438356161633139623633326137316234373539303738626639306362653466626133353435383234353466303434356263336262386533653463353837

Upvotes: 0

Views: 914

Answers (1)

Guillaume Roux
Guillaume Roux

Reputation: 7308

Just use BigInt.parse or BigInt.tryParse and set its radix parameter to 16:

String hex = "dad85aac19b632a71b4759078bf90cbe4fba354582454f0445bc3bb8e3e4c587";
BigInt bin = BigInt.parse(hex,radix: 16);

Upvotes: 3

Related Questions