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)

6
votes
1answer
23 views

Implementing checksum add without carry in C

I need to write a function in C which performs a checksum using the rule "add without carry". As I understand it, the "add without carry" concept is equivalent to the bitxor operator and given that ...
7
votes
1answer
112 views

Bit shifting and masking

I was wondering if someone could review this simple bit of code that originally was in C++, but now converted to C# as practice in using bit-shifting and creating a sort of a quasi-array functionality....
4
votes
3answers
52 views

A simple assembly program to count the number of ones in a register

I made a simple assembly program to count the number of ones in a register. Since this is basically my first ever, I would like to hear what I can improve or if there are some major flaws in this one: ...
3
votes
1answer
64 views

Packing and unpacking bits (2)

Part 1 here. I improved my code from my previous question (linked above). ...
6
votes
2answers
112 views

Packing and unpacking bits

Part 2 here. I wrote this class for packing data. Would it benefit from being named BitPacker rather than BitStream (and change write/read to pack/unpack), or it works as is? How can I improve it? ...
1
vote
1answer
32 views

Using JavaScript-bitwise AND and -bitwise NOT for setting a number to 0

Obviously is the XOR-operator is used in low-level programming-languages used a lot for setting a value back to all bits 0. For example: 11010 ^ 11010 => 00000 Brought my teacher to figuring a out ...
4
votes
5answers
124 views

Test four int of commonality in the lower four bits

The four parameters a, b, c and d can be ...
2
votes
0answers
39 views

Bit string builder for Java

I have this Java class for building bit strings. The set of methods it provides resembles that of java.lang.StringBuilder. See what I have: BitStringBuilder.java: ...
4
votes
1answer
46 views

LEB128 in Haskell

I have implemented the LEB128 encoding for unsigned integers. I'm fairly new to Haskell so I have some doubt about the coding style I'm using, particularly the definition of ...
1
vote
0answers
30 views

Convert tri-gram of type wchar_t to an integer type

I am trying to convert a tri-gram containing 3 characters of type wchar_t to an integer type (an uint64_t at the present time). ...
1
vote
3answers
473 views

Calculating the 'binary gap' of a number

Inspired by this question and therefore this one I decided that clearly the best most readable way to solve this is with Regular Expressions. A binary gap within a positive integer N is any ...
1
vote
0answers
24 views

Implement “at” lens for Data.Map

I've been working on adding an operation like Data.Lens.At.at to Data.Map. This uses an extremely fast, extremely small, and ...
1
vote
3answers
51 views

Byte array to floating point such as FPE2 in Java

Apple's System Management Controller uses FPE2 and SP78 as floating-point formats. While writing a Java library that that interfaces with the SMC, I ported someone's C function to convert read a FPE2-...
4
votes
3answers
234 views

Finding the fastest common prefix of 2 strings in Python

I'm comparing my algorithms, slice_prefix and bit_prefix, with existing ones to find the common prefix length of 2 strings as ...
1
vote
0answers
46 views

A bitwise common prefix algorithm in Python

Is my algorithm slow because it has problems? Or, is any bitwise common prefix solution not going to give me the performance I'm looking for? After profiling my algorithm, I found that over 60% of ...
10
votes
1answer
204 views

Console app to teach bitwise operators

I'm creating a console app that has the purpose to teach you how to use C# bitwise operators. I have several classes which contain info about the different operators and I instantiate/add them in the ...
3
votes
1answer
63 views

Parsing an IP address (Bit manipulation)

Given a string representing of an IP address, such as "127.43.23.59", return a 32 bit integer representation of this string. The 32 bit integer is separated into four bytes, where each byte is one of ...
7
votes
1answer
280 views

Calculating the results of bit operations

I have a simple program that calculates and outputs the results of all the bit operators. I'm planning to send it to my friend and to explain some stuff about them to him. Before I do that, I want to ...
2
votes
1answer
432 views

Printing longest sequence of zeroes

I am doing a coding exercise in codility and I came across this question: A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ...
1
vote
2answers
78 views

Concatenate three 16-bit integers in one 64-bit integer with C++

I am looking for an elegant alternative of the following code where wordXX contains always 16 bits: ...
7
votes
2answers
62 views

Portable byte order conversion

I'm trying to improve the portability of a file format converter, specifically to POSIX platforms other than Linux. I'd appreciate a review of the following functions used for converting between ...
4
votes
0answers
47 views

Parallel popcount of packed bytes

I want to do a popcount of bytes in an array. Not a total popcount of everything, but lots of little popcounts for every individual byte to determine the neighborhood count in GoL. The following ...
0
votes
2answers
48 views

BMP writer in C

I recently wrote a BMP writer in C: bmpWriter.h ...
3
votes
3answers
86 views

Bit manipulation tool set

I made a tool set to facilitate bit manipulation as follows. Any comments are welcome, be it about the interface design, the implementation, or even the naming. Also, I want to make sure that the tool ...
4
votes
1answer
95 views

Speeding up the generation all bit strings with Hamming distance one

I'm playing around with hypercubes. For this, I need to create its edge set. Specifically, the edge set is the set of all bit strings with Hamming distance 1. An important property is that I want to ...
0
votes
1answer
87 views

Saturated signed addition

So this a exercise from the book COMPUTERS SYSTEMS A PROGRAMMERS PERSPECTIVE I need to add two signed numbers and in case it overflows or underflows return ...
10
votes
2answers
106 views

Simulation of image transfer over noisy channel

Following this question, I've tried to rewrite some core methods to avoid using String for bit operations, and I ended up using ...
4
votes
1answer
174 views

Solution to part 1 of Day 7 Advent of Code in Scala

Does someone want to review my solution to part 1 of Day 7 Advent of Code in Scala? The assignment is here: http://adventofcode.com/day/7 Without repeating the whole text, in short: Given a text file ...
2
votes
0answers
110 views

FUTABA SBUS serial communication in C++

I would like to reimplement the current Futaba SBUS protocol in ArduPilot for Navio+. It seems to be a relatively expensive protocol, so I changed the code from an existing git project and to make it ...
3
votes
1answer
43 views

Routine for convert decimal digits to Densely Packed Decimal

I've written an amd64 assembly routine (in gas syntax using the System V calling convention) to convert three decimal digits to densely packed decimal because I wasn't satisfied by the performance of ...
3
votes
5answers
84 views

Toggle four relays on/off based on bitmap stored in uint8_t

I am using a one-byte bitmap to control four relays. I am writing a function which will take the bitmap stored as uint8_t, look to see which bits are set/cleared, ...
0
votes
1answer
212 views

Remove elements existing in a list built from an enum

The objective of this code is to make the difference inbetween two lists of items, that is knowing which items are missing in the second list in regards to the first one. The first list is built from ...
2
votes
3answers
82 views

Testing if the binary representation of an integer has an odd number of ones

The fn odd_ones(x: u32) -> bool function should return true when x contains a odd number ...
7
votes
2answers
138 views

All arithmetic operator functions (+, -, *, /, %) coded only using bitwise operators in C

Here's all the functions in C that does all the arithmetic operators without using arithmetic operators themselves, mostly using bitwise operators. Recursive functions and comparison operators are ...
2
votes
1answer
51 views

Three ways to read a number for a BitInputStream

I'm trying to learn how to write more readable code without introducing easily avoidable performance killers. This is part of a BitInputStream Java class I'm ...
3
votes
1answer
37 views

PWM wave generation

This code takes a integer x of range [0,127] as input, returns an array of four 32-bit integers, with x bits set. I'm trying to ...
3
votes
1answer
63 views

Testing for divisibility of numbers - follow-up

(Here is the follow up question) I had another go at trying to speed up my program described in my previous question. JS1's answer was particulary helpful and now my code is only about 20% slower ...
2
votes
2answers
83 views

Program to test for divisibility of numbers

(EDIT: here is the follow up qusetion) Using this program to test for the smallest number where its permutations or itself is divisible by 10 or less numbers is twice as slow as the fastest program I ...
5
votes
3answers
377 views

Finding nearest power of 2

I have the following simple program which calculates and returns the nearest power of 2 of a given number. Because I use increments and decrements to find the closest power, this takes a very long ...
2
votes
0answers
167 views

Read bits, write bits data to arbitrary position in char array

I created functions to read bit data from arbitrary bit position of a char array to long long int, and I also created a function ...
1
vote
1answer
162 views

Bitmask type to perform binary operations

Without any specific implementation details, how would you create a bitmask type that wraps binary arithmetic into something easy to read? Ideally, this would be used with an ...
1
vote
1answer
165 views

“Flipping bits” Python implementation

Problem Statement You will be given a list of 32 bits unsigned integers. You are required to output the list of the unsigned integers you get by flipping bits in its binary representation (i.e. ...
7
votes
1answer
104 views

Return Y integer with same bit sets as X & having | X - Y | minimum value

I happened to come across one question: Given an integer 'x' (Only positive), write an algorithm that returns integer 'y' such that it has the same number of bits set as 'x' and is not equal ...
3
votes
1answer
73 views

Code Chef problem COOKMACH

Firstly, I got the solution for this question in CodeChef, but I noticed one thing which still confuses me. This was the code which was accepted as correct. ...
6
votes
1answer
142 views

Reading bits from a stream from least to most significant

For a recent project I was in need of excessive bit manipulation. Specifically, I had to write to or read from a variable number of bits up from the least significant bit towards the most significant ...
0
votes
3answers
116 views

Performing add/delete/count operations on a list

Problem Statement (HackerRank) You have a list of integers, initially the list is empty. You have to process Q operations of three kinds: add s: Add integer s to your list, note that ...
4
votes
2answers
613 views

Division without multiplication, addition or division

In context of preparing for a coding interview, I gave the division problem a go using Java. This is what I came up with. It's a little bit different to other solutions I've come across the interweb. ...
5
votes
8answers
2k views

String reversal, capitalize vowels, lowercase consonants

This was a portion of a skills test given to me by a company. The task was to write a method that takes a string, reverses it, and sets the vowels as capitals and consonants to lowercase. I was also ...
3
votes
3answers
674 views

Number of right cyclic shifts to give the biggest number

I am preparing to coding interview and I met this task today: You are given 30-bit unsigned integer N. A right cyclic shift of N by K bits is the result of performing a right cyclic shift of N by one ...
3
votes
3answers
333 views

Mockup in C of hardware implementation for multiplication of signed integers

I challenged myself to implement multiplication of signed integers using only +, -, >>,...