Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1287 How can I mask certain bits of an integer?

You are here: irt.org | FAQ | JavaScript | Number | Q1287 [ previous next ]

Use the logical &:

<script language="JavaScript"><!--
var Num = 99;

var result = (99 & 0xAA);

document.write(result);
//--></script>

If however you want to create a binary mask using 0's and 1's then use:

<script language="JavaScript"><!--
var Num = 99;

var result = (99 & parseInt('10101010', 2));

document.write(result);
//--></script>

©2018 Martin Webb