sensortoy/app/test.html

35 lines
615 B
HTML
Raw Normal View History

2016-05-20 16:10:40 +00:00
<script>
2016-05-20 16:17:29 +00:00
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
2016-05-20 16:10:40 +00:00
2016-05-20 16:17:29 +00:00
// http://www.ti.com/lit/ds/symlink/opt3001.pdf
var x = 15390;
var v = 15 << 10;
2016-05-20 16:10:40 +00:00
2016-05-20 16:17:29 +00:00
var r = x & v;
var o = x & ~v;
console.log('x',x.toString(2));
console.log('r',r.toString(2));
console.log('o',o.toString(2));
2016-05-20 16:10:40 +00:00
var m;
for (var t=0;t<16;t++)
{
2016-05-20 16:17:29 +00:00
m = v >>> t;
2016-05-20 16:10:40 +00:00
console.log(m.toString(2), t);
2016-05-20 16:17:29 +00:00
console.log(x.toString(2));
2016-05-20 16:10:40 +00:00
}
for (var t=0;t<16;t++)
{
m = v << t;
2016-05-20 16:17:29 +00:00
console.log(m.toString(2), t);
console.log(x.toString(2));
2016-05-20 16:10:40 +00:00
}
</script>
a[0] | (a[1] << 8)