Created
February 18, 2018 21:05
-
-
Save nurpax/d2dc245340136f06aa9439df78cd4219 to your computer and use it in GitHub Desktop.
jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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