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)

4
votes
3answers
64 views

Bitstream reader

I have a program which reads and analyses MPEG-TS files. I've been using gperftools to identify hotspots and optimize them, and 45% of all samples at this point are in my main bitstream reader ...
8
votes
3answers
119 views

Fastest sum of absolute values of 32 differences

A long should be treated as a list of 32 unsigned numbers, each of them just two bit long. So 0x1234F... represents ...
7
votes
1answer
94 views

Gray codes addition — Take 2

For a while, I have tried to find ways (known or new) to do stuff with Gray codes. As some of you probably know, I already tried to implement an algorithm to add two Gray codes without having to ...
2
votes
2answers
160 views

Simple Binary Adder

The program adds two binary numbers in two' s complement ignoring the overflow for a constant size of bits. I am trying to generalize the program by taking input from the user in a single line without ...
2
votes
2answers
61 views

Given bit strings, perform a bitwise addition

I'm looking for code-review, optimizations and best practices. This code is a Java adaptation of code on geeksforgeeks.org. Please verify if space complexity is \$O(n)\$ where n is number of bits, and ...
2
votes
1answer
49 views
2
votes
1answer
57 views

Byte-to-binary conversion function

My implementation of a binary-to-bits converting function: ...
10
votes
2answers
207 views

Calculating holes on a Tetris grid quickly

I have created a Tetris AI which can play Tetris on its own given a set of rules. It places the next piece in every possible way on the board, and calculates which position that gives the fewest ...
3
votes
1answer
45 views

Network byte order to host byte order

While doing a little project involving sniffing packets, I found myself programming a cross platform network to host byte order and host to network byte order, this is my first time developing a ...
8
votes
2answers
229 views

Packing and unpacking two 32-bit integers into an unsigned 64-bit integer

Does this look good for combining/retrieving two 32 bit integers (a type and an index) into/from an unsigned 64 bit integer (a unique ID)? The point is to hide in the API the composition of the ...
4
votes
1answer
148 views

Optimizing code to find maximum XOR in Java

This problem is from HackerRank (not a competition, just for practice) Basically what you do is take in two integers as a range and then finding the maximum XOR from a pair of integers in that ...
7
votes
1answer
498 views

An Army of Ones

I've been practicing using recursion lately and thought this was a case where it would prove really useful, is this good use or is there some superior non-recursive way to go about it? Challenge: ...
4
votes
1answer
94 views

Bitwise operators for permissions

I'm trying to create a read-write-execute permissions system for items using user-group-world system. I already have the user/group system set up, just not the permissions. This is what I wrote: ...
2
votes
1answer
103 views

XOR of a list of a numbers

In preparing a solution for the CodeChef "Will India Win" challenge, I am trying to find out the xor of list of numbers. The first line of input contains the number of test cases, 1 ≤ T ≤ 106. ...
3
votes
1answer
61 views

Copy arbitrary number of bits at arbitrary offset from buffer to another buffer

I have just written a function copy_lowbits_off to copy any number of bits (not bytes) from a source buffer to a destination buffer. The function also supports ...
0
votes
1answer
67 views

Portable bitfields code generator

I am working on a project that involves quite a lot of instantiated objects, with tons of properties, most of which have only a few possible values, so the prospect of saving on memory is quite ...
4
votes
5answers
663 views

Reversed Binary Numbers

Here is my code for "Reverse Binary Numbers" in C. Problem Your task will be to write a program for reversing numbers in binary. For instance, the binary representation of 13 is 1101, and ...
7
votes
7answers
541 views

Changing element visibility based on multiple checkbox states

I am writing a script in JavaScript & HTML and have some optimization problems. In the for, loop I check a variable named ...
7
votes
2answers
105 views

Speed optimization for transparent gradient blend algorithm

The following algorithm works correctly for the purposes that I need, which is to set the top side of an image with a transparent gradient blend. Any tips to optimize it for speed? ...
4
votes
2answers
777 views

Binary to decimal number converter

Here I am doing some exercises for my studies with Python. This is a binary to decimal number converter (currently restricted to that). These are the very first steps, so there is no error handling. ...
2
votes
2answers
193 views

Computing pairwise bitwise OR in a list of bit-strings

I am trying to solve this problem using Clojure: You are given a list of \$N\$ people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. ...
16
votes
2answers
388 views

Gray codes addition

As some of you know, I have been working with Gray codes and am trying to design a good gray_code class in modern C++. I will end up posting several parts of the ...
3
votes
1answer
96 views

Implementing binary output to a file in C++11

I would like to have a class which supports outputting bits into a file. This is what I came up with but I fear there are many poor decisions. Should I inherit from a ...
10
votes
2answers
180 views

Embedded C# bitpacked arrays to low-level STM32F4 driver for GE G35 RGB LED Christmas tree light

I'm going to be opensourcing some code I'm working on. I don't need help with the code, I just want to make sure my code is readable and my comments make sense. I have a knack for the esoteric. ...
8
votes
1answer
227 views

Mostly portable 128 by 64 bit division

I wrote this out of curiosity. It is based on the theory behind Knuth's Algorithm D and is intended to emulate the behavior of the x86 div instruction (though the ...
8
votes
1answer
152 views

Saving bytes instead of objects to write smaller files

This question is about reducing the size of files saved to disk in an infinite world 2D mining game. I finally added code to my game to save and load distant chunks instead of keeping all of them ...
6
votes
2answers
105 views

Count bits that differ between integers X and Y

I'm trying to solve the following problem : You are given two integers, X and Y. Calculate the number of bits that will be changed in order to convert integer X to integer Y. Here is my ...
10
votes
1answer
228 views

Logical shift with signed numbers

I am going through the Coursera course The Hardware/Software Interface and because it has already ended, I would not be able to get any feedback on the code. The assignment is: LogicalShift: ...
8
votes
2answers
142 views

Lossy packing 32 bit integer to 16 bit

I am working on the lossy 16 bit representation for 32 bit integers that catches all 32 bit range with precision depending on absolute value. My idea is to store integer ...
11
votes
1answer
750 views

Steganography for images

For a school project I'm working on a small library to do steganography. I've just finished the first method of steganography and thought I'd get some feedback. This steganography method works by ...
7
votes
2answers
152 views

Array-like container for uints shorter than 8 bits (Rev 1)

This is a follow-up to Array-like container for uints shorter than 8 bits In short: The PackedBitfieldArray should be a kind of container for packed (unsigned) ...
11
votes
1answer
146 views

Array-like container for uints shorter than 8 bits

Follow-up: Array-like container for uints shorter than 8 bits (Rev 1) First of all: yes, I need this kind of array to generate data for a piece of hardware, and it must be stored and manipulated ...
19
votes
3answers
1k views

Diamond in the rough! Finding Gems in the rocks

Recently a question was asked that solved a hackerrank problem: Counting gems amongst the rocks The description of the challenge is: John has discovered various rocks. Each rock is composed of ...
2
votes
1answer
96 views

Bitwise operation to get the weekday name

The function days_name receive a val (string) corresponding to weekdays in hexadecimal. ...
3
votes
2answers
173 views

Emulating __uint128_t

I developed a lot of code locally with __uint128_t only to find out that it is not available on the target platform. I am now trying to write my own struct that ...
7
votes
1answer
257 views

Hexadecimal to RGB conversion

I am trying to convert hex to rgb, and rgb to hex. My current code doesn't seem optimal, and there is an issue with 0's in the hexadecimal. What do you think about the overall quality of this code? ...
8
votes
2answers
2k views

Validating UTF-8 byte array

I'm writing a validator function that receives a byte[] and checks whether it represents a valid UTF-8 byte sequence, according to this table. Is my approach ...
4
votes
4answers
292 views

BitShift code compacting

I'm new to Java programming and am really enjoying it. I made a bitshift program, but I think it's too long. I expect the program to: Let users input the number and degree to be shifted Specify if ...
6
votes
1answer
610 views

Implementing Karatsuba Multiplication Algorithm in Python

I am trying to implement Karatsuba multiplication algorithm for binary (base 2) numbers. A requirement is that the intermediate / final results must also be in binary so as to assist in educative ...
10
votes
3answers
416 views

Finding the largest of a series of numbers being XORed

I'm working on solving a problem involving finding the largest of a series of numbers being XORed. This is the actual problem: Xorq has invented an encryption algorithm which uses bitwise XOR ...
8
votes
3answers
111 views

Check if bit is only set once in a vector of int

I have a vector of uint16_t and I want to check if there is a bit which is only set in one vector. I then get its position within the vector as well as from the ...
5
votes
2answers
468 views

Why are these functions slower than BigInteger's included methods?

I tried writing alternative functions to Java's BigInteger.add(BigInteger.ONE), BigInteger.add(BigInteger), and ...
3
votes
1answer
112 views

Finding the 'Minimum' AND of all the possible subsets of a set

The subset size should be greater than or equal to 2. How can I speed up this code? ...
15
votes
3answers
1k views

Converting an IP

I've written a DNS tool in Node and would like to know if there's a better and more efficient way of handling the conversion from an IP to a long. I'm not too good at bitwise just yet and would like ...
3
votes
2answers
277 views

Function for splitting an integer into smaller values

This is the function I've implemented in an answer to this question. I've tried to make this as simple and idiomatic as possible, using C++11. Could this still be improved in any way? ...
4
votes
2answers
92 views

Is there a more optimal way to approach some of these bitwise functions?

I completed some bit manipulation exercises out of a textbook recently and have grasped onto some of the core ideas behind manipulating bits firmly. My main concern with making this post is for ...
5
votes
1answer
94 views

Template for endianness-free code, data always packed as BIG-Endian

It's been a while since I've been properly grilled about my code. I had this Idea which should probably never make it into production code but still I couldn't find anything seriously wrong with it ...
5
votes
2answers
379 views

Implementations of rotate, shift, XOR, NOT and AND

I am going through the example of SHA256 over at Wikipedia and wanted to make sure I understood all the operations of the manipulation math before trying to actually attempt the implementation itself. ...
1
vote
2answers
33 views

Displaying data as binary in C with bitmasks

I wrote a program to display data in memory as binary and it worked. (It gave me immense sense of satisfaction and joy to see this work. I guess this happens to newbies who are just testing the ...
0
votes
4answers
723 views

Arithmetic or logical right shifts

Is this code correct? Is there any major improvement I can ad in terms of number of operations? ...