Posts Tagged bitwise

C++ For C# Developers: Part 42 – Numbers Library

Tags: , , ,

There are so many kinds of numbers we deal with on a regular basis and the C++ Standard Library has a full suite of tools to deal with them. Today we’ll look into random numbers, ratios, mathematical constants, bit manipulation, complex numbers, and more!

Read the rest of this article »

2 Comments

Sub-Byte Sizes: Part 2

Tags: , ,

Today we continue to explore how we can store values in less than a byte. We’ll expand the BitStream struct with the capability to write values in addition to just reading them. Read on to see how to implement this functionality and for the full source code which you can use in your projects.

Read the rest of this article »

2 Comments

Sub-Byte Sizes: Part 1

Tags: , ,

The smallest a C# type can be is one byte. The byte type and and an empty struct are examples of this. But what if we want to store data in less than a byte to improve performance such as load times and CPU cache utilization? Today’s article does just this by packing at the bit level!

Read the rest of this article »

2 Comments

Optimizing with Bit Twiddling Hacks

Tags: ,

Stanford’s Sean Eron Anderson has a great page titled Bit Twiddling Hacks. This is a great resource for C programmers looking to employ bitwise operators (& | ^ ~ << <<< >> >>> etc.) to speed up their code. But what about AS3 programmers? We have bitwise operators too, but will the same tricks work for us? Today’s article ports some of these bit twiddling hacks to AS3 and tests to see if any ground is gained.

Read the rest of this article »

14 Comments

Converting Numbers to Ints

Tags: , , , , , ,

This is an extremely common task: converting a Number to an int. There are a lot of ways to do it, but which is fastest in AS3? Today we’ll look at a performance test app that attempts to find the fastest way to accomplish this. The answer just may surprise you!

Read the rest of this article »

14 Comments

Bitwise Alternatives to Multiply, Divide, and Modulus: Faster?

Tags: , ,

Many programmers are aware of a special case where you can use a bitwise shift for multiplication or division when you’re multiplying or dividing by a power of two. For example, you can replace i * 2 with i << 1 and i / 2 with i >> 1. A lesser-known trick works for modulus. But are these alternatives actually any faster? Today's article puts them to the test!

Read the rest of this article »

15 Comments

Faster Logic With Bitwise Operators

Tags: , , , , ,

Logical operators are necessary in every app, so it’s unfortunate that they are so slow in AS3. That’s why I was happy to see a potential alternative in a recent comment by Skyboy. Today’s article shows you how to do logic faster by avoiding logical operators (e.g. &&) and using their bitwise (e.g. &) operator counterparts instead.

Read the rest of this article »

25 Comments