Bitwise refers to a bitwise operation which operates on one or more bit patterns or binary numerals at the level of their individual bits.

learn more… | top users | synonyms (1)

12
votes
4answers
458 views

Counting number of 1's and 0's from integer with bitwise operation

Is there a better way of doing this? // Definition: Count number of 1's and 0's from integer with bitwise operation // // 2^32 = 4,294,967,296 // unsigned int 32 bit #include<stdio.h> int ...
3
votes
2answers
119 views

Function for reading bits

I've made this simple function for reading N bits from an unsigned char* (with a possible offset) and I'm willing to share it here, get a review, suggestions for improving it, etc... typedef struct ...
0
votes
0answers
22 views

Could this ROM reader be faster and/or smaller?

I've been practicing arduino programming for a few weeks now having become confident in reading and writing to pins so I decided to take it a step further and do a serious project that does both, so ...
2
votes
2answers
74 views

Copy and bit-invert ints in an std::vector

I want a second copy of an std::vector in which all elements are inverted, e.g. 0x01 in the first vector should be 0xFE in the second. Is this a good solution? std::vector<uint8_t> first_list ...
2
votes
1answer
125 views

Take all the bits in a number and shift them to the left end

I wrote this program which takes all the bits in a number and shifts them to the left end (for example: 01010110 --> 11110000). It's and exercise from a book. It works, but it seems to be very ...
3
votes
3answers
354 views

Split a long integer into eight 4-bit values

It's an exercise from a book. There is a given long integer that I should convert into 8 4-bit values. The exercise is not very clear for me, but I think I understood the task correctly. I googled ...
1
vote
0answers
50 views

10x10 bitmapped square with bits

This program prints out a 10x10 square and uses only bit operations. It works well, but I don't like that global array. Can you tell me if the code is proper or not? #include <iostream> ...
0
votes
0answers
91 views

Playing with bits using Java

How can I optimize the following class? prepareSharing packs bits on left and prepareMask counts the required bits for encoding integers between zero and max. public class KeyFactory { ...
1
vote
1answer
108 views

Missing element from array (D&C) - code design/aesthetic improvement

I am trying to implement in C/C++ a 'classical' Divide and Conquer algorithm which solves the following problem "Given an array of n-1 numbers (int) from 0 to n, find the missing number". I am using ...
0
votes
1answer
83 views

Bitwise Logic optimization

I should be able to figure this out on my own, but I can't seem to wrap my head around how to optimize this set of logic for interpreting the existence of URL parameters. Below is my code: <cfif ...
1
vote
1answer
84 views

Color fading function

I found this old color fading function in my snippets folder and would like to implement it to one of my projects. It can be used to fade one color to another. It's a very long one-liner: D3DCOLOR ...
3
votes
2answers
575 views

Speed up a program to find the minimum Hamming distance

I have a solution to the puzzle at https://kattis.csc.kth.se/problem?id=codes. What can I do to make my algorithm much much faster? What the algorithm does is take an N×K matrix and search for the ...
2
votes
5answers
579 views

Performance: Divide group of numbers into two groups of which the sums are equal

I have a piece of code that divides a group of numbers into two groups of numbers of which the sums are equal. I created this because of a StackOverflow question: ...
1
vote
0answers
190 views

JavaScript xor function

I made simple JavaScript xor function. It accepts string, numeric array and mixed array (char, string, num) as params. It returns string or an array. Returning an array is a must!. All numbers are ...
2
votes
1answer
97 views

Simplify bit flags checking code

Please help make this code more cleaner. It's a part of window procedure that notifies my renderer before client area of window resized. I need to check two combinations of bit blags: some of them ...
4
votes
1answer
297 views

Bitwise Flag code for Python

I am looking for feedback on this compact Python API for defining bitwise flags and setting/manipulating them. Under the hood, FlagType extends int and all operations are true bitwise, so there is ...
-1
votes
1answer
44 views

What are these bitwise operations doing? [closed]

I found a snippet of code on the PHP manual which packs 64 bit integers. APparently this is necessary because pack() always treats numbers as 32 bit integers even on 64 bit architectures. I don't ...
0
votes
2answers
720 views

Spotify's “Reversed Binary Numbers” Problem [closed]

I wrote some Java code for Spotify's Reversed Binary Numbers puzzle and I tested it on my machine and I am almost positive that it behaves as expected. However, when I send it to puzzle AT spotify.com ...
3
votes
1answer
293 views

Connect Four: Bitboard checking algorithm

I'm rather new to Clojure and so I decided to program a Connect Four for fun and learning. The code below is a Clojure implementation of this bitboard algorithm. The whole code can be found here: ...
2
votes
3answers
2k views

Base-36 encoding of a byte array

After posting a question about Alphanumeric Hash generation on StackOverflow, the most helpful answer was to change the conversion method from pulling 5-bit chunks of a binary hash value, to instead ...
1
vote
1answer
120 views

What specific optimizations can be made to this BitArray class, and how can they be implemented?

Here is the current code for the BitArray class needing optimization (implemented on big integers): import itertools ################################################################################ ...
3
votes
1answer
463 views

speeding up an algorithm that find patterns in a growing collection

I want to find a way to speed up this code. if you look at the condition of If calculated Then in the code below, this is what slowing down the code. While the code provided seem fast with Const ...
4
votes
3answers
486 views

How to manage a bit array with C programming langage?

I'm training a bit with C, and I'm trying to build a bit array. I would like to have some comments about my code, because I'm not sure that it's the best way to do it. // BAL.c #include ...
3
votes
4answers
421 views

Counting the number of bits of a positive integer

How can I improve this code for counting the number of bits of a positive integer n in Python? def bitcount(n): a = 1 while 1<<a <= n: a <<= 1 s = 0 while ...
3
votes
1answer
315 views

BitVector Class: Performance

Lately, I've been reading up on the Common Language Infrastructure's data formats. As a result, one thing it mentioned is some of the data is stored in a BitVector. I hadn't ever used a BitVector ...
5
votes
1answer
317 views

Jon Bentley's bitmap sort implementation

I've implemented Jon Bentley's bitmap sorting algorithm from Column 1 of his Programming Pearls book. This code supports user-defined integer range (works from Integer.MIN_VALUE to Integer.MAX_VALUE), ...
3
votes
2answers
485 views

bit rotation code review

I'm studing C on K&R and I solved exercise 2.08 ("Write a function rightrot(x,n) that returns the value of the integer x rotated to the right by n positions") with the code below. I've tested my ...
36
votes
8answers
7k views

Fastest way to clamp an integer to the range 0-255

I'm working on some image processing code that can generate pixel values outside of the normal range of 0 to 255, and I'd like to clamp them back into the valid range. I know that there are saturating ...
3
votes
1answer
216 views

Print Bits Part II|: Coding Feedback Wanted

The last question I have been playing around with is a right rotate. I think it is also called a barrel roll. Anyways if you have a better solution please post. I am still learning the art of bit ...
7
votes
2answers
100 views

Print Bits Part II: Coding Feedback Wanted

Does anyone have a shorter more simple way of doing this? /* * Next write a function invert(x,p,n) that returns x with the n bits * that begin at position p inverted, leaving the others unchange ...
15
votes
8answers
2k views

Copying 80 bytes as fast as possible

I am running a math-oriented computation that spends a significant amount of its time doing memcpy, always copying 80 bytes from one location to the next, an array of 20 32-bit ints. The total ...