Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <bitset>
using namespace std;
int main() {
cout << "* Left Bitshift: \n";
int a = 3; bitset<8> x(a);
cout << "a = \t\t" << a << "\t" << x << "\n";
cout << "a <<= 2 is \t" << (a <<= 2) << "\t" << (x <<= 2) << "\n\n";
cout << "* Right Bitshift: \n";

Quick Bitwise Operation Primer

BitShifting

<<= and >>= are bit shifting operators.

<<= shifts the bits so that they are more significant, while >>= shifts them so they are less.

For example:

@br0xen
br0xen / partitionon.js
Created March 14, 2014 14:18
devict.org Code Challenge - Partition On
function partitionOn(pred, items) {
var sp_idx = 0;
for(var i in items) {
if(!pred(items[i])) {
// If the predicate is false, move it to sp_idx, otherwise, leave it.
items.splice((sp_idx++), 0, items.splice(i, 1)[0]);
}
}
return sp_idx;
}
@br0xen
br0xen / bowling.js
Last active August 29, 2015 13:57
devict.org Code Challenge - Bowling Score
/* bowling.js - Track a bowling score
* devict.org coding challenge.
* To see it in action go to:
* http://dev.bullercodeworks.com/bowling.html
*/
// To keep bowling score, we must first write a DOM manipulation framework.
function B(els, attrs) {
// Turn 'this' into an array of passed in elements.
function B(els) {
#define A printf
main(){int n=0,i;while(n++<100){i=0;n%3==0?A("fizz"):i++;n%5==0?A("buzz"):i++;i>1?A("%d\n",n):A("\n");}}
@br0xen
br0xen / formatOrdinal.js
Created June 11, 2013 19:24
Ordinal Number formatting in Javascript
Number.prototype.formatOrdinal=function(){var n=this,s=["th","st","nd","rd"],v=n%100;return n+(s[(v-20)%10]||s[v]||s[0])};
@br0xen
br0xen / max_subarray.py
Created May 6, 2013 20:16
Submission for the 2013-05-03 UpFront Code Challenge
def max_subarray(A):
max_ending_here = max_so_far = 0
neg_high = A[0]
all_neg = True
for x in A:
if x > 0:
all_neg = False
break
else:
if x > neg_high:
@br0xen
br0xen / SignatureView.java
Created August 31, 2012 18:32
SignatureView for Android
public class SignatureView extends View {
private static final float STROKE_WIDTH = 5f;
/** Need to track this so the dirty region can accommodate the stroke. **/
private static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2;
private Paint paint = new Paint();
private Path path = new Path();
@br0xen
br0xen / formatPercent.js
Created May 25, 2012 14:28
Percent Formatter for JavaScript Number Prototype
Number.prototype.formatPercent=function(d,sym){var n=this,d=d==undefined?0:d,sym=sym==undefined?"%":sym;return ""+(Math.round(n*(Math.pow(10,d)))/(Math.pow(10,d)))+sym;};
@br0xen
br0xen / formatMoney.js
Created May 25, 2012 14:27
Money Formatter for JavaScript Number Prototype
Number.prototype.formatMoney=function(c,d,t,sym){var n=this,c=isNaN(c=Math.abs(c))?2:c,d=d==undefined?",":d,t=t==undefined?".":t,s=n<0?"-":"",i=parseInt(n=Math.abs(+n||0).toFixed(c))+"",j=(j=i.length)>3?j%3:0,sym=sym==undefined?"$":sym;return sym+s+(j?i.substr(0,j)+d:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+d)+(c?t+Math.abs(n - i).toFixed(c).slice(2):"");};