Giter Club home page Giter Club logo

binary.dart's Introduction

Hi, I'm Matan

Software engineer, tech lead, and engineering manager in recovery.

I'm a staff software engineer at Google working on Flutter. I believe in:

  • Test driven development
  • Outcomes over intentions
  • Idiomatic code

... I'll spend some more time on this page soon ๐Ÿ˜…

binary.dart's People

Contributors

kharland avatar leynier avatar matanlurey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

binary.dart's Issues

Release 2.0.0 on pub

Just a reminder to myself.

I suspect there will be more changes I want to get in before publishing.

Add <BinaryInt>.replaceBitRange(left, right, bits)

... as an easier way to replace a range of bits in an int:

extension BinaryInt on int {
  int replaceBitRange(int, left, int right, int bits);
}

void example(int bits) {
  bits.replaceBitRange(4, 0, 0x1b);
}

Allow extending Integral

... i.e. to create Uint3, Uint12, and other data structures I'd like!

(They don't make sense in this library, but letting users create their own seems OK)

Deal with >32-bit integers

I.e. the result of 0xffffffff + 0xffffffff.

Most of the current bit operations have undefined behavior, especially across the VM and JS.

Rename "shiftRight" to "signedShiftRight"

Perhaps also add signedShiftLeft.

Docs should also be updated so that << >> and >>> are correctly stated:

  • << Zero-fill left shift
  • >> Signed right shift
  • >>> Zero-fill right shift

Conflict with the Flutter SDK because it depends on meta v1.7.0

In the upgrade to v3.0.0, the meta package was upgraded to v1.8.0, causing a conflict with the Flutter SDK in the stable channel because Flutter depends on meta v1.7.0, but in the master branch, it already depends on meta v1.8.0. So, which option is considered the best?

  • Downgrade the meta version to v1.7.0
  • Wait for the Flutter upgrade

PS: Using dependency_overrides we can evict the issue meanwhile.

[Feature] Provide bit constants

Hi, i needed to do some bitmasking at compile time where possible and it would be great if the library provided constant for bits, for example:

class CompatibleBits
{
  /// The largest possbile unsigned integer that is valid in JavaScript.
  static const MAXJSUINT = ALLBITSSET53;
  static const ALLBITSSET53 = 0x1fffffffffffff;

  // Javascript shift operations works on 32 bit values only.
  static const int bit1 = MAXJSUINT & 1 << 0;
  static const int bit2 = MAXJSUINT & 1 << 1;
  static const int bit3 = MAXJSUINT & 1 << 2;
  static const int bit4 = MAXJSUINT & 1 << 3;
  static const int bit5 = MAXJSUINT & 1 << 4;
  static const int bit6 = MAXJSUINT & 1 << 5;
  static const int bit7 = MAXJSUINT & 1 << 6;
  static const int bit8 = MAXJSUINT & 1 << 7;
  static const int bit9 = MAXJSUINT & 1 << 8;
  static const int bit10 = MAXJSUINT & 1 << 9;
  static const int bit11 = MAXJSUINT & 1 << 10;
  static const int bit12 = MAXJSUINT & 1 << 11;
  static const int bit13 = MAXJSUINT & 1 << 12;
  static const int bit14 = MAXJSUINT & 1 << 13;
  static const int bit15 = MAXJSUINT & 1 << 14;
  static const int bit16 = MAXJSUINT & 1 << 15;
  static const int bit17 = MAXJSUINT & 1 << 16;
  static const int bit18 = MAXJSUINT & 1 << 17;
  static const int bit19 = MAXJSUINT & 1 << 18;
  static const int bit20 = MAXJSUINT & 1 << 19;
  static const int bit21 = MAXJSUINT & 1 << 20;
  static const int bit22 = MAXJSUINT & 1 << 21;
  static const int bit23 = MAXJSUINT & 1 << 22;
  static const int bit24 = MAXJSUINT & 1 << 23;
  static const int bit25 = MAXJSUINT & 1 << 24;
  static const int bit26 = MAXJSUINT & 1 << 25;
  static const int bit27 = MAXJSUINT & 1 << 26;
  static const int bit28 = MAXJSUINT & 1 << 27;
  static const int bit29 = MAXJSUINT & 1 << 28;
  static const int bit30 = MAXJSUINT & 1 << 29;
  static const int bit31 = MAXJSUINT & 1 << 30;
  static const int bit32 = MAXJSUINT & 1 << 31;

  // We can use exended bits until 53 bits are used.
  // shift is not working past 32 bits in javascript but
  // we cant still use the precision bits.
  static const int bit33 = 0x100000000;
  static const int bit34 = 0x200000000;
  static const int bit35 = 0x400000000;
  static const int bit36 = 0x800000000;
  static const int bit37 = 0x1000000000;
  static const int bit38 = 0x2000000000;
  static const int bit39 = 0x4000000000;
  static const int bit40 = 0x8000000000;
  static const int bit41 = 0x10000000000;
  static const int bit42 = 0x20000000000;
  static const int bit43 = 0x40000000000;
  static const int bit44 = 0x80000000000;
  static const int bit45 = 0x100000000000;
  static const int bit46 = 0x200000000000;
  static const int bit47 = 0x400000000000;
  static const int bit48 = 0x800000000000;
  static const int bit49 = 0x1000000000000;
  static const int bit50 = 0x2000000000000;
  static const int bit51 = 0x4000000000000;
  static const int bit52 = 0x8000000000000;
  static const int bit53 = 0x10000000000000;
}

I then can use these to give a name to options with these constants (sadly dart doesnt support constant getters or functions)

class Options
{
  static const int option1 = CompatibleBits.bit1;
  static const int option2 = CompatibleBits.bit2;

  int getOptionsForThing()
  {
      return option1 | option2;
  }
}

i would be great to have this on the library, without throwing or checks, as performant as possible.
Or with enums.

Add `toggleBit` (or similar)

I.e.

bits.toggleBit(30, true /* or false */)

Currently implemented elsewhere as:

extension IntegralX<T extends Integral<T>> on Integral<T> {
  T toggleBit(int bit, bool set) {
    return set ? setBit(bit) : clearBit(bit);
  }
}

replaceBitRange seems to have bugs

print(psr.toBinaryPadded());
if (i.allowChangingFlags) {
  psr = psr.replaceBitRange(31, 24, op.bitRange(31, 24).value);
}
print(psr.toBinaryPadded());
00000000000000000000000000010000
>>>>>
00000000000000000000000000000000

... it shouldn't have changed the lower bits at all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.