Do I need to study about bitwise operators and interfaces for computer

My computer text book is from APC(class 10 only since school said that the first 9 chapters are the same in grade 9), but it seems to lack some stuff from grade 9 and I'm confused since there are no bitwise operators or interfaces mentioned and I saw questions related to them in a few sample papers. Idk if they're actually needed.

If they are can anyone also send some PDFs or images about the mentioned topics

👍︎ 3
💬︎
📅︎ Dec 07 2021
🚨︎ report
vilmos 2.1.1 UPDATE - New Documentation, Types standardization, Bitwise operators, ... github.com/Vinetwigs/vilm…
👍︎ 7
💬︎
👤︎ u/Vinetwigs
📅︎ Nov 17 2021
🚨︎ report
Need help understanding bitwise operators

I read a few articles and kind of understood the basics of how the bitwise operator & works.

But what I don't understand is why we have been asked to use (buffer[3] & 0xf0) == 0xe0 when instead we can just use (buffer[3] & 0xe0) == 0xe0 ?

Can't seem to wrap my head around it :(

👍︎ 3
💬︎
📅︎ Nov 09 2021
🚨︎ report
vilmos 2.1.1 UPDATE - New Documentation, Types standardization, Bitwise operators, ... github.com/Vinetwigs/vilm…
👍︎ 4
💬︎
👤︎ u/Vinetwigs
📅︎ Nov 17 2021
🚨︎ report
vilmos 2.1.1 UPDATE - New Documentation, Types standardization, Bitwise operators, ... github.com/Vinetwigs/vilm…
👍︎ 4
💬︎
👤︎ u/Vinetwigs
📅︎ Nov 18 2021
🚨︎ report
vilmos 2.1.1 UPDATE - New Documentation, Types standardization, Bitwise operators, ... github.com/Vinetwigs/vilm…
👍︎ 5
💬︎
👤︎ u/Vinetwigs
📅︎ Nov 17 2021
🚨︎ report
Use of bitwise and operator, &=, in Quest 6

Here is my understanding of how the bitwise and operator is being used in the draw functions (corrections or clarifications welcome!)

Using the and bitwise operator (&=) will ensure that boolean value will remain 'false' if ever it is compared with a false value. ie It will be 'true' until compared with a 'false', whereupon it will be 'false' ever after.

Once a line or shape is drawn outside the screen it is now forever 'uncontained' by the screen. ie contained = 'false' ever after.

👍︎ 2
💬︎
👤︎ u/aaron_d0
📅︎ Nov 11 2021
🚨︎ report
The Time I (Sorta) Had a Real Use Case for a Bitwise Operator in JavaScript macarthur.me/posts/use-ca…
👍︎ 170
💬︎
📅︎ May 22 2021
🚨︎ report
Question about floating point deconstruction, float field extraction, and float reconstruction example from Rust in Action using bitwise operators

I probably could have picked a more succinct title. I'm reading the book Rust in Action and am enjoying it thus far. Having come from dynamically typed languages, it's been a really interesting read! There's an example (Listing 5.9) in the book that extracts the fields of a float (sign, exponent, and mantissa).

The part I'm curious is why the "AND mask" operations are being used. The following code is from the function from listing 5.9 (I added comments and line numbers for convenience):

21|  let bits = n.to_bits(); // bits == 1000010001010011010111000010100

23|  let sign = (bits >> 31) & 1;
     // bits >> 31 as binary == 0, 0 & 1 == 0
     // sign as binary == 0

24|  let exponent = (bits >> 23) & 0xff;
     // bits >> 23 as binary == 10000100, 0xff as binary == 11111111
     // exponent as binary == 10000100

25|  let fraction =  bits & 0x7fffff;
     // bits (binary) == 1000010001010011010111000010100
     //      0x7fffff == 0000000011111111111111111111111
     // fraction as binary == 1010011010111000010100

I get that for the Mantissa, the goal is to strip away the signed bit and the bits representing the exponents (hence why 0x7fffff's length is shorter than bits' length). But why do we need to use the "AND mask" for lines 23 and 24 if they end up evaluating to the same thing?

Thank you in advance!

👍︎ 16
💬︎
📅︎ Jul 24 2021
🚨︎ report
Bitwise Operators are << .. dammit i mean >> arithmetic
👍︎ 131
💬︎
📅︎ May 18 2021
🚨︎ report
When bitwise operators can be useful for game development?

For those who don't know, bitwise operators are operators for manipulating bits in your program.

https://en.wikipedia.org/wiki/Bitwise_operation

They are cool, but when it would be useful in a game project?

👍︎ 7
💬︎
📅︎ May 23 2021
🚨︎ report
Coding Shorts: Demystifying Bitwise Operators in C# (Video) youtube.com/watch?v=qWCUo…
👍︎ 89
💬︎
📅︎ Mar 28 2021
🚨︎ report
Using Bitwise Operators in Programming

Hi everyone! I am comfortable with basic questions that use bitwise operators to solve questions like duplicate number, counting number of bits set in a number.. Etc

But i am not really able to wrap my head around these concepts for multiple other problems like finding subsets etc. The usage of bitwise operators is not at all intuitive to me.

Could someone pls suggest what needs to be done to get comfortable with these to start identifying and applying them by myself?

👍︎ 6
💬︎
📅︎ Jun 05 2021
🚨︎ report
ELI5: bitwise operators

I was reading on /r/python about the snippet of code that creates a 32Tb pyc file and someone asked what << does.
The reply was very dense and in my experience bitwise operator explanations are always very complex.
Is there an ELI5 version that will help me understand them?

👍︎ 110
💬︎
👤︎ u/dasfreak
📅︎ Feb 17 2021
🚨︎ report
Bitwise Logic and the Modulo Operator make some pretty carpet patterns youtu.be/YfE53QK5fwA
👍︎ 37
💬︎
📅︎ Jun 12 2021
🚨︎ report
When bitwise operators are useful?

Can you show me some examples of when bitwise operators are useful?

For examples I mean code. I still don't got it. I've passed my entire afternoon searching examples on the internet but I found nothing useful and clear

👍︎ 3
💬︎
📅︎ May 23 2021
🚨︎ report
I don't understand why bitwise Operators are efficient in Big O?

Could someone explain me the logical reasoning of why bitwise Operators are efficient in Big O?

Like as an example program of checkBit(int a, int b), where is an integer input number and b represents the bit position of a in binary, so if its 1, it just returns 1 or true something like that... if its done using bitwise operator, why does its time complexity better with just single statement like ==> (a >> b)%2 or (a>>b) & 1 or (a << b) & a ??

👍︎ 3
💬︎
👤︎ u/ChiTech121
📅︎ May 29 2021
🚨︎ report
Same operator for logical and bitwise operations.

Do you think it's a good idea to use the same operator for logical and bitwise operations?

1 &amp; 5 -&gt; 1 (bitwise)

true &amp; false -&gt; false (logical)

The same for | (or) ^ ( xor).

It sort of converges when using vectors.

{true, false, false} &amp; {true, true, false} -&gt; {true, false, false}

It only works if the language is strictly typed. Anything else I may miss?

Little nitpick is, ^ is now used, so power would need to be pow() or **.

Are there languages such syntax?

Edit: Thanks for the great inputs. It seems short-circuiting is the biggest concern. Functions in my language have no side effects. So I think it is less of an issue. (Short-circuit is in fact an optimization pass). My language has no pointers so the common "test for nullptr and dereference" does only seldom happen with optionals. Then it's just a sensible left to right evaluation.

👍︎ 49
💬︎
👤︎ u/danybittel
📅︎ Nov 05 2020
🚨︎ report
Coding Ada: Bitwise operators craftofcoding.wordpress.c…
👍︎ 23
💬︎
👤︎ u/thindil
📅︎ Jan 19 2021
🚨︎ report
[C++] Need explanation on how "&" bitwise operator can be used to check for oddity

Suppose I have:

int oddOrNot = 0;
oddOrNot = 5 &amp; 1; 

How is the "&" being used to check for oddity? I know & represents the AND logical operation, but I'm unsure what that has anything to do with oddity and how that would even work...

👍︎ 10
💬︎
👤︎ u/tranderman
📅︎ Nov 05 2020
🚨︎ report
Which bitwise operator(s) should I use to change the LSB in a byte?

For example, I have 01100010 stored in an unsigned int, and I want to change the LSB, here it is 0, to 1. Just that, and nothing else. How would I go about doing this?

Also, let's say in a different case, if the LSB is 1, and I want to change it to 0, would the code be the same?

👍︎ 8
💬︎
📅︎ Nov 11 2020
🚨︎ report
Bit operations without bitwise operators

To account for XY problem the X question is as follows:

This is a task in structs and unions topic.

Write functions that do bit operations on 32-bit unsigned integer.

int toggle_bit(uint32_t* pvalue, int b);
int set_bit(uint32_t* pvalue, int b);
int clear_bit(uint32_t* pvalue, int b);
int isset_bit(const uint32_t* pvalue, int b);

Functions are to take pvalue pointer to a number and a bit number. They should return -1 in case of incorrect input and 0 on success with exception of function isset_bit which should return 0 or 1 if given bit is set or not. You may not use bit-wise operators, allocate memory or use [] operator except array declarations. Write a program that takes number, bit number and operation number (0 - toggle, 1 - set, 2 - clear, 3 - check if set) and then prints edited number in hexadecimal format (for operation 0-2) or 0/1 in decimal (for operation 3).

The Y question is:

I have written this functions that I think do work but I am really not satisfied with the solution. Pasting only toggle_bit function because the rest is very similar.

union bits_set {
    uint8_t bit_val;
    struct {
        uint8_t bit0 : 1;
        uint8_t bit1 : 1;
        uint8_t bit2 : 1;
        uint8_t bit3 : 1;
        uint8_t bit4 : 1;
        uint8_t bit5 : 1;
        uint8_t bit6 : 1;
        uint8_t bit7 : 1;
    } bits;
};

union bytes_set {
    uint32_t value;
    union bits_set bytes[4];
};

int toggle_bit(uint32_t* pvalue, int b)
{
    if (pvalue == NULL || b &lt; 0 || b &gt; 31) return -1;

    union bytes_set bytes;
    bytes.value = *pvalue;

    union bits_set *dst_byte = (bytes.bytes + b / 8);
    uint8_t dst_bit = b % 8;

    if      (dst_bit == 0) dst_byte-&gt;bits.bit0 = (dst_byte-&gt;bits.bit0 + 1) % 2;
    else if (dst_bit == 1) dst_byte-&gt;bits.bit1 = (dst_byte-&gt;bits.bit1 + 1) % 2;
    else if (dst_bit == 2) dst_byte-&gt;bits.bit2 = (dst_byte-&gt;bits.bit2 + 1) % 2;
    else if (dst_bit == 3) dst_byte-&gt;bits.bit3 = (dst_byte-&gt;bits.bit3 + 1) % 2;
    else if (dst_bit == 4) dst_byte-&gt;bits.bit4 = (dst_byte-&gt;bits.bit4 + 1) % 2;
    else if (dst_bit == 5) dst_byte-&gt;bits.bit5 = (dst_byte-&gt;bits.bit5 + 1) % 2;
    else if (dst_bit == 6) dst_byte-&gt;bits.bit6 = (dst_byte-&gt;bits.bit6 + 1) % 2;
    else if (dst_bit == 7) dst_byte-&gt;bits.bit7 = (dst_
... keep reading on reddit ➡

👍︎ 2
💬︎
📅︎ Dec 09 2020
🚨︎ report
Ruby Bitwise Operators medium.com/rubycademy/rub…
👍︎ 11
💬︎
📅︎ Apr 17 2021
🚨︎ report
Rotate bits using bitwise operators?

I have a binary number and I want to rotate the bits from left to right 1 bit at a time.

eg: 1 0 1 -> 0 1 1 ->1 1 0- > 1 0 1

other sites like geeks for geeks use (n << 1) | (n >> (INT_BITS - 1)). This gives a wrong answer for me.

The geeks for geeks tutorial says when we left shift by one bit, the first bit just disappears. but in my python interpreter the number is multiplied by 2.

geeks for geeks: 1 0 1 -> 0 1 0

my python interpreter: 1 0 1 -> 1 0 1 0

Please tell me the working code for rotating the bits

Thanks in advance.

👍︎ 4
💬︎
📅︎ Dec 19 2020
🚨︎ report
Help with understanding bitwise operators in context

I have a code snippet which I don't fully understand. I tried walking through the code with the debugger, but I still don't get it.

This is taken from the Android SDK of Godex, a printer manufacturer. It is part of a decompiled class, so this might be why the syntax is so interesting?

This part of the code is supposed to send an image to the printer. It is part of a bigger function, but I just added the relevant part. I don't understand the use of constructedByte.

To me the | operator (bitwise OR) just increase the variable by 1 and the << (bitwise shift to the left) just doubles it. What does one end up with in data at the end? So what is the byte object constructedByte supposed to represent in the end?

int height = 100;
int weidth = 100;

ArrayList&lt;Byte&gt; data = new ArrayList();
String qcommand = "Q" + px + "," + py + "," + y + "," + height + "\n";
byte[] startingBytes = qcommand.getBytes();

int y;
for(y = 0; y &lt; startingBytes.length; ++y) {
    data.add(startingBytes[y]);
}

int x;
for(y = 0; y &lt; height; ++y) {
    for(x = 0; x &lt; y; ++x) {
        byte constructedByte = 0;

        for(int j = 0; j &lt; 8; ++j) {
            constructedByte = (byte)(constructedByte &lt;&lt; 1);
            int widthPixel = x * 8 + j;
            if (widthPixel &lt; width) {
                int pixel = pixels[y * width + widthPixel];
                if (pixelBrightness(pixel) &lt; 127) {
                    constructedByte = (byte)(constructedByte | 1);
                }
            }
        }

        data.add(constructedByte);
    }
}
👍︎ 3
💬︎
👤︎ u/kiraora
📅︎ Jan 18 2021
🚨︎ report
Explaining Bits & Bitwise Operators in C youtu.be/FOff_YvqpjE
👍︎ 9
💬︎
👤︎ u/bonj0v1
📅︎ Mar 10 2021
🚨︎ report
So, is this how binary addition when using bitwise operators work?

I have been trying to understand how actually binary addition using bitwise operators AND, and XOR, work and I think I finally understand it, after spending almost a day thinking about it :P What confused me actually was when I tried creating the algorithm in my head, is this correct? thoughts

👍︎ 14
💬︎
📅︎ Dec 12 2020
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.