Click here to Skip to main content
15,896,207 members
Everything / Bitwise

Bitwise

bitwise

Great Reads

by Dheeraj Singh Bhadoria
This Artical shows that how we can change the color of any image throw Bitmap
by Thomas Daniels
This article explains how bitwise operators work and this article explains also several purposes of them with examples in C# and VB.NET.
by honey the codewitch
Easily shift bits in memory of arbitrary length, declare integer sizes programmatically, endian conversion, and more

Latest Articles

by honey the codewitch
Easily shift bits in memory of arbitrary length, declare integer sizes programmatically, endian conversion, and more
by Thomas Daniels
This article explains how bitwise operators work and this article explains also several purposes of them with examples in C# and VB.NET.
by Dheeraj Singh Bhadoria
This Artical shows that how we can change the color of any image throw Bitmap

All Articles

Sort by Score

Bitwise 

18 Jul 2015 by enhzflep
Simple.y = y | 2; //set Bit 1y = y | 128; // set Bit 7Consider the binary representation of the first few digits.0 = 0000 00001 = 0000 0001 *2 = 0000 0010 *3 = 0000 00114 = 0000 0100 *5 = 0000 01016 = 0000 01107 = 0000 01118 = 0000 1000 *Notice the ones marked with...
4 Jun 2021 by CPallini
The function returns the value of the loc bit of the integer variable num. Note you could rewrite it this way int float_bit_return(int num, int loc) { return ((num >> loc) & 1); } (the inner braces are not needed due to C operator...
13 Nov 2013 by CPallini
Dim index1, index2, result As UShort index2 = &H10index1 = &HD result = index1 + (index2
14 Nov 2015 by Richard MacCutchan
See https://www.google.com/search?q=operator%20overloading%20c%2B%2B[^].
4 Dec 2015 by Kobayashi Porcelain
I have a university assignment i need some help with. Don't give me the solution; hints or small portions of code would be appreciated.So, my university project is all about unicode. To be exact, I have to write code that takes character input in utf-16 format, converts it to utf-8 and...
4 Dec 2015 by Sergey Alexandrovich Kryukov
First, you did not show how your objects named char… are declared. You need to do all the calculations on 32-bit unsigned integer; in other cases, the size would be not enough to represent a code point beyond BMP.I did not check up UTF16 part, but at least one part is missing: there...
15 Mar 2022 by Greg Utas
The term "embedded system" can refer to anything from a toaster to a special purpose server whose source runs to tens of millions of lines of code, so it's hard to say much without knowing what kinds of embedded systems you mean. That said,...
22 Mar 2013 by Dheeraj Singh Bhadoria
This Artical shows that how we can change the color of any image throw Bitmap
13 Nov 2013 by ArunRajendra
Try this. I think there is logic issue with the way you are setting the bits. In my opinion thsi should be bit valuesAll =111 opera=001chrome =010 safari=100select UserAgent&4 from @bitswhere UserAgent&4=4
14 Nov 2014 by den2k88
You can't have 255 as a result with your code because in each case you are taking the last 5 bits of the 555 color and multiplying it by 8.This way you can have as a maximum source color the value of 31dec (11111bin), wich multiplied by 8 gives off exactly 248.Remeber that you are trying...
14 Nov 2014 by JJMatthews
Hello, I could really use a little help from one of you bitwise gurus. I trying to add 16 bit capabilities to a function to greyscale an image inplace that I use for generating a disabled toolbar imagelist. I found and tried tried 2 different methods;The first one returns me a RGB value...
22 Jul 2015 by CPallini
I would use the BitArray class[^].
22 Jul 2015 by _Asif_
Your fundamental question is how to switch to the binary world in C#! And the answer is once you know the theory of Boolean Algebra[^] it would be like a peiece of cake! Deep down its all mathematics, seeing your code it seems like you have not reviewed these concepts. Once you understand...
27 Mar 2019 by Member 14198125
I have a raw12 file(4096 * 3072 ) where RGGB(odd rows RGRG..And even GBGB...) Pixels are stored ,12 bit for each .I have to use only 5 bit MSB data from each 12 bit data , I have to take 64 bit at a time for cache optimization and use bit manipulation to get 5 MSB bits for each 12 bit pixel,I...
26 Mar 2019 by Rick York
I would try to make things simpler and functional first and then address the speed. Speed means nothing when the code doesn't work in the first place. Try something like this : const int width = 4096; typedef union { UCHAR byte; struct nibble { ...
15 Mar 2022 by CHill60
This is a quick answers forum and your questions can't really be answered quickly. I recommend acquiring a good book on the subject e.g. Programming Embedded Systems in C and C++: Amazon.co.uk: Michael Barr: 9781565923546: Books[^] or Embedded C...
11 Oct 2012 by Muhammad Idrees GS
Hi, I am working on a chess application and need to create opening book, a file which could contains a millions of moves and positions. we have 64 squres, some of which have occupied by pieces while some are empty. Let we represent our pieces with following bits (using to Huffman encoding...
11 Oct 2012 by Frederico Barbosa
Try this website:http://stackoverflow.com/questions/1831386/programmer-puzzle-encoding-a-chess-board-state-throughout-a-game[^]and more specifically this one:http://www.cforcoding.com/2009/12/programming-puzzles-chess-positions-and.html[^]
21 Mar 2013 by Saurabh.Garg
I used this one for my C++ projects:Zip Utils - clean, elegant, simple, C++/Win32[^]-Saurabh
13 Nov 2013 by Member 3493606
I need to read if a bit on position x is set.So for instance I want to check if useragent = chromeI try:select UserAgent from bits where UserAgent &3 =4I get nothing. How do I get just the chrome from bits table (00000111)?00000001 = all00000011 = opera00000111 = chrome00001111...
14 Jul 2014 by Sergey Alexandrovich Kryukov
You need to OR those bits together: http://en.wikipedia.org/wiki/Operators_in_C_and_C++#Bitwise_operators[^].For example 1 | (1
14 Jul 2014 by CPallini
Quote:num|(1
22 Jul 2015 by Member 11856803
I spent long time understanding how programmers use the advantage of speedy binary representation of data in C# arrays but I just dont get it.for example If I have 2 arrays A, and B to store 0/1 data. In normal situation we do like this : bool flag=true; int[] A = new int[10] {...
14 Nov 2015 by MaxySpark
How can I overload > bitwise operator in c++?
13 May 2017 by Richard MacCutchan
int int_bits(unsigned x) { return count_bits(~0U); } That looks wrong, since it will return the same value for any value of x . I suggest changing it to: return count_bits(x);
13 May 2017 by Patrice T
Quote: C program to convert decimal to binary using bitwise and, shift operator The program do not convert, it just display the value in base 2. Note that internally, integers are stored in binary in C programs. To know what are & and ~, just read the documentation about 'bitwise operators'....
25 Jun 2018 by Andy Lanng
Hi, I'm working on a project where efficiency of the search functionality is critical. I have several flag columns (like enum flags in c#). Searching on this data is super fast (3 milliseconds round trip) but I've come-a-cropper now I have to perform group counts. So, I have an item 'A'...
25 Jun 2018 by Andy Lanng
Ok - I think I've worked out the best solution: I tries a view with a cte: with cte as ( select cast(1 as bigint) as flag, 1 pow union all select POWER(cast(2 as bigint),pow), pow + 1 from cte where flag
25 Jun 2018 by Kornfeld Eliyahu Peter
SELECT VAL, COUNT(*) FROM ( SELECT COLOR AS COLOR_VAL, COLOR & 1 AS [1], COLOR & 2 AS [2], COLOR & 4 AS [4], COLOR & 8 AS [8], COLOR & 16 AS [16], COLOR & 32 AS [32], COLOR & 64 AS [64], COLOR & 128 AS [128] FROM (SELECT 73 AS COLOR UNION SELECT 53 UNION SELECT 91) AS...
16 May 2020 by Jacxx
I have a List/array with some integers. array = {1,2,3,4,5,7,11,14,15...} for each integer that exists in the array/list from 1 to 8 i append a bit until 1 byte and then convert the binary to decimal. In this case 11111010(6 and 8 does not...
14 May 2020 by Richard MacCutchan
Something like the following will capture eight bits at a time: int pattern = 0; for ( // expression to iterate over your list { if ( // if the value exists { pattern |= 1; } pattern
16 May 2020 by George Swan
I did something similar when encrypting data using the BitArray class. Hope this is of some help static void Main(string[] args) { List numbers = new List { 1, 2, 3, 4, 5, 7 };//, 11, 14, 15 int max =...
17 May 2020 by Patrice T
Your code to set bits look rather complicated. First of all you need to know that an integer is stored in base 2, the integer is a field of bits. example of 10! 10= 1*2^3+0*2^2+1*2^1+0*2^0 bits are numbered from right to left, starting with bit...
19 Sep 2020 by Patrice T
Comments in code is a good habit, continue. Quote: 0x3048 = 0111 0000 0100 1000 Since 0x3048 is 0011 0000 0100 1000 and 0111 0000 0100 1000 is 0x7048 your example is rather confuse. Rewrite what you want to do with following notation: Take a...
19 Sep 2020 by KarstenK
Your code is confusing by using offsets and not starting with zero as first index. I think you have a bug in your code. In the case of perfomance problems: I would use some constants or macros and avoid an (expensive) function calls. tip: Write...
15 Mar 2022 by Member 15314815
I have some C, C++ programming skills which can be utilized for building embedded applications in real time. I am working on learning C, C++ programs for developing embedded applications in real time. As I do not have full time work experience in...
20 Nov 2022 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
8 Sep 2016 by Thomas Daniels
This article explains how bitwise operators work and this article explains also several purposes of them with examples in C# and VB.NET.
18 May 2021 by honey the codewitch
Easily shift bits in memory of arbitrary length, declare integer sizes programmatically, endian conversion, and more
19 Sep 2020 by Member 14942281
I am looking to implement the prototype for read_and_write, but couldn't get it right. Any help is appreciated. I am able to extract bits. In this below code for write_val1, my intent is to write only the first 9 bits of final_val into...
21 Mar 2013 by Matthew Faithfull
There are two things here, working with data compression and working with C++. To crack data compression you'll nee to understand the mathematics and algorithms at least reasonably well from a theoretical point of view, in other words on paper. A quick search tells me I might start somewhere...
20 Jul 2015 by Sergey Alexandrovich Kryukov
Are you serious? It's 2 == 1
19 Jul 2015 by Patrice T
Everything is in bitwise operation meaning.In the cpu, integers are stored in a binary form. it means that each bit hold the value of a power of 2.bit 0 has the value of 2^0, bit 1 has the value of 2^1 and so on.10 (base 10) is 1010 (base 2) which is 1*2^3+ 0*2^2+ 1*2^1+ 0*2^0...
12 Nov 2013 by Member 8525993
Hi if I got an array of 2 number that represent a hex number index2 = 0x10 index1 = 0xD can someone tell me how to combine these two numbers so i can get the hex value 100D i try the below code Dim index1, index2, result As Short index2 = &H10 index1 =...
18 Jul 2015 by User 11060979
It is an easy thing...after get familar with it, but this needs its time.In short:0 && 0 == 00 && 1 == 01 && 0 == 01 && 1 == 1Longer Version, but Overkill to start:https://en.wikipedia.org/wiki/Boolean_algebra[^]Simpler...
12 Nov 2013 by Sergey Alexandrovich Kryukov
You cannot possibly have an array of numbers representing HEX numbers. You can either have array of string each representing a number, but this is not an array of numbers. Of you can have an array of numbers, but a number cannot be "hex" or "decimal". A number is a number, always "binary". So,...
14 Jul 2014 by Jeevan83
I know that in order to set a bit we use num|(1
18 Jul 2015 by 0xF4
unsigned char y = 0x0; y = y | 1; //Set Bit 0 y = y | 8; //Set Bit 3 y = y &~1; //Clear Bit 0 y = y &~8; //Clear Bit 3I was reading on bitwise op's, and got confused by one thing, `y = y | 1` sets the Oth bit to 1, how do you set the 1st bit to one? How do you do the last?...
21 Mar 2013 by Alamgirable
Where is the best place to start working with data compression in c++.I want to compress data ontwo endpoints on one endpoint i want to compress data and on other i want decompress.Please help me.
8 Mar 2015 by A4Abhiraj
I'm so sorry for not providing a proper description. This is my first post here.This is a project that embeds text inside a bitmap. I'm editing the Least Significant bits of the RGB components skipping every fourth component just in case the image isn't 24 bits. I debugged the code many times...
13 May 2017 by Member 13188016
this code is an example from a book that the problem require to change decimal to binary number using bitwise AND oeprator and shift operator. i cannot understand the code although had tried to understand this code using debug compiler. suppose for a and b, user input is 10 and 8 #include...
7 Dec 2020 by Christian Bale
You are given a sequence A1,A2,…,AN and you have to perform the following operation exactly X times: Choose two integers i and j such that 1≤i
7 Dec 2020 by Member 15014657
this is my solution, however this does not pass all the test case don't know why plz help: import math for i in range(int(input())): N,X = map(int,input().split()) L = list(map(int,input().split())) count = 0 curr = 0 ...
4 Jun 2021 by Rahul Dicholkar
int float_bit_return(int num, int loc) { return (num & 1
20 Nov 2022 by Ronny ronny
you are given two integers N and K, and you need to find two positive integers X and Y such that: X