0

I'm trying to develop an app to convert text to binary (and vice versa) in dart language. It'll be my first flutter app. I found dart:convert library can do this but I still don't know how to make it work. Could use some help. Thanks!

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

1 Answers1

0

https://api.flutter.dev/flutter/dart-core/String/codeUnits.html please use it.

or

https://pub.dev/packages/binary_codec library will help you as well you can use it like this :


  /// 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???');
  }
Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
Abhishek Ghaskata
  • 1,802
  • 2
  • 6
  • 11
  • 1
    `String.codeUnits` returns a UTF-16 representation of the string. If using a binary format, I would strongly recommend against using that if possible since that means endianness becomes relevant, which might entail adding a BOM. For binary interchange, prefer UTF-8. – jamesdlin Sep 20 '20 at 18:40