Skip to content

Instantly share code, notes, and snippets.

@nurpax
Created February 18, 2018 21:05
Show Gist options
  • Save nurpax/d2dc245340136f06aa9439df78cd4219 to your computer and use it in GitHub Desktop.
Save nurpax/d2dc245340136f06aa9439df78cd4219 to your computer and use it in GitHub Desktop.
jsx
// NOTE only up to 5 bit numbers are supported
function makeFormula (bits) {
const superscripts = ['\u2070', '\u00B9', '\u00B2', '\u00B3', '\u2074']
const nbits = bits.length
const parts = bits.map((b,idx) => {
const boffs = nbits - idx - 1
return b.toString() + '\u22C5' + '2' + superscripts[boffs]
})
return parts.join(' + ')
}
const BitExample = ({bits}) => {
return (
<View>
<BitGrid
rows={[bits]}
nBits={bits.length}
/>
<AppText style={{marginTop: 5}}>= 0b{bits.map(b => b.toString())}</AppText>
<AppText>= {makeFormula(bits)}</AppText>
<ImpactText>= {bits.reduce((acc, b) => (acc << 1) + b, 0)}</ImpactText>
</View>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment