如何在dart中将文本转换为Binary(颤振)?

时间:2020-09-20 13:08:04

标签: flutter dart

我正在尝试开发一个应用程序,以使用dart语言将文本转换为二进制(反之亦然)。这将是我第一个扑扑的应用程序。 我发现dart:convert库可以做到这一点 ,但我仍然不知道如何使它工作。可以使用一些帮助。谢谢!

示例:https://www.rapidtables.com/convert/number/ascii-to-binary.html

1 个答案:

答案 0 :(得分:0)

https://api.flutter.dev/flutter/dart-core/String/codeUnits.html 请使用它。

https://pub.dev/packages/binary_codec库也将为您提供帮助 您可以像这样使用它:


  /// Encode the generated data
  Uint8List encoded = binaryCodec.encode(exampleObject);

  /// Decode the encoded data
  var decoded = binaryCodec.decode(encoded);

  /// Check if they are the same
  if (exampleObject.toString() == decoded.toString()) {
    /// They should be the same
    print('Success');
  } else {
    /// Else theres a bug in the library
    /// Please send the [exampleObject] that leads here and on which 
    /// platform you are to the author of this library (stefan.zemljic@gmx.ch)
    print('Wait... What???');
  }