Skip to content

Instantly share code, notes, and snippets.

@lelandrichardson
Created August 27, 2020 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lelandrichardson/5f69f4bf4af7169a59ac0596c4f08358 to your computer and use it in GitHub Desktop.
Save lelandrichardson/5f69f4bf4af7169a59ac0596c4f08358 to your computer and use it in GitHub Desktop.
fun Address(
$composer: Composer,
$static: Int,
number: Int, street: String,
city: String, state: String, zip: String
) {
Text($composer, ($static and 0b11) and (($static and 0b10) shr 1), "$number $street")
Text($composer, ($static and 0b100) shr 2, city)
Text($composer, 0b1, ", ")
Text($composer, ($static and 0b1000) shr 3, state)
Text($composer, 0b1, " ")
Text($composer, ($static and 0b10000) shr 4, zip)
}
@ShreckYe
Copy link

I don't know what the compose compiler actually generates but shouldn't the first bit mask be 0b1 instead of 0b11? Though they both produce the same result, 0b11 means extrating the first 2 bits whose second bit is just erased out with the second and, compared to which 0b1 is just more straightforward. Additionally, 0b1 also consists better with those bit masks afterwards such as 0b10, 0b100, 0b1000, and 0b10000.

@ycmjason
Copy link

I agree @ShreckYe. I got a little confused when trying to understand too. Thanks for pointing this out! @lelandrichardson can you confirm please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment