Questions tagged [bitwise]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
96 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 ...
1
vote
1answer
1k 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 ...
1
vote
1answer
3k 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. ...
1
vote
3answers
168 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 ...
1
vote
2answers
219 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 waters)...
1
vote
1answer
182 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): ...
1
vote
1answer
35 views

LeetCode Count number of set bits solution

Question - Write a function that takes an unsigned integer and return the number of '1' bits it has (also known as the Hamming weight). ...
1
vote
1answer
76 views

Go command-line tool to do some simple byte manipulation

I have some files containing 16-bit words in big-endian order, and a tool to process them that assumes little-endian order. I therefore need to swap the order of each pair of bytes in my files. This ...
1
vote
1answer
213 views

Adder method of a binary calculator

This is the adder method of my binary calculator. I did not cover for the case that someone passes a non binary number into the calculator yet. I am pretty sure I have covered every other edge case ...
1
vote
1answer
64 views

Bit pattern to console output

This function will draw a card in the console ...
1
vote
1answer
984 views

Pixel bit-wise LSB extraction to byte array

I wrote the following code below to extract the least significant bit (LSB) of each pixel and store it into a byte[] array. I was wondering if Java has a more ...
1
vote
0answers
121 views

Sending data from UART to microcontroller via AT89C2051 functioning as a UART/SPI bridge

I have an unusual setup. I have an AT89S52 microcontroller in which its UART is used by the PC. I needed a way to make a second UART based device work with it, so what I decided to do was make a UART ...
1
vote
1answer
2k views

Forced and easy hton/ntoh conversion

Context: When sending message across the network, the sender has to convert the message from host byte order to network byte order and the receiver has to do the the reverse - network order to host ...
1
vote
0answers
134 views

Getting TLE for SPOJ Bitplay challenge program

I have tried a naive way to solve this problem: Given a even number N (N ≤ 109) and an integer K, you have to find the greatest odd number M less than N such that the sum of digits in binary ...
1
vote
0answers
83 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 ...
0
votes
4answers
2k views

Arithmetic or logical right shifts

Is this code correct? Is there any major improvement I can ad in terms of number of operations? ...
0
votes
2answers
792 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: ...
0
votes
2answers
841 views

BMP writer in C

I recently wrote a BMP writer in C: bmpWriter.h ...
0
votes
2answers
2k 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 ...
0
votes
1answer
211 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. ...
0
votes
1answer
73 views

Adding bits, simpler

Considering that two bitsets are provided in the form of strings, char a[] and char b[], as in the code below. And the task of ...
0
votes
1answer
4k 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 ...
0
votes
1answer
43 views

Implementing carryless multiplication using normal multiplication

In carryless multiplication the partial products are XORed (ie addition without carry) together rather than added normally. The partial products themselves are still the product of a power of two (...
0
votes
1answer
28 views

Given an integer, return its binary representation. You cannot use any Integer.toXXXString methods

Here is my code: ...
0
votes
1answer
55 views

Kademlia bucketing

Kademlia is a DHT (distributed hash table) which uses a specific type of routing table, dependent on the Hamming distance between the "addresses" of two peers on the network. I'm attempting to ...
0
votes
1answer
88 views

ANDing ints in Java [closed]

Is there any better way than doing: if ((newState & InputState.DEFAULT) == InputState.DEFAULT) ? My InputState.class defines static int variables to the ...
0
votes
1answer
146 views

Portable bitfields code generator [closed]

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 ...
0
votes
0answers
64 views

Add two inputs in base and return result in array [closed]

The input of the method is two inputs in base: each input is given as array of its digits in that base. The method should add the inputs and put the result in outDigits (if there is an overflow,...
-1
votes
2answers
66 views

Given an integer number, invert its bits. You cannot use the ~ operator

Here is my code: ...
-1
votes
1answer
40 views

Interlock of some equipments in electrical power system using simple Arduino Uno code

I'm trying to implement some logic functions essential to control a small power system consisting of 2 Transformers labeled T1 and T2, 2 Generators (G1 and G2) and a bus tie (BT). I'm not going to ...
-4
votes
3answers
154 views

Multiplying many times

I needed to find away to left shift a number on a platform with buggy << and >> bitwise operators. I came up with a ...