## Bit-fields and Bitwise operators

Bit-fields and Bitwise operators
# 1
04-23-2002
Bit-fields and Bitwise operators

Hi,
Is it possible to use bitwise operators in bit fields?
For example:

typedef struct Mystruct {
unsigned char A :1 ;
unsigned char B :1 ;
} Mystruct;

and assume

struct Mystruct STR_1S, STR_2S, tempSTRS = {0};

then the following line:

tempSTRS = STR_1S & STR_2S;
gives the error:

operants must have integral type: op "&"

One way to overcome the problem is to perform the bitwise operations in each member separelty i.e.
tempSTRS.A = STR_1S.A & STR_2S.A;
tempSTRS.B = STR_1S.B & STR_2S.B;

Is there any other more eficient way?
 amatsaka View Public Profile for amatsaka Find all posts by amatsaka
# 2
04-23-2002
Looks more like homework.. ?
If it is hope you did check the Forum rules. No Homework/Assignments allowed.
 killerserv View Public Profile for killerserv Find all posts by killerserv
# 3
04-23-2002
No it's not a homework.

I am a software engineer for the last for years
 amatsaka View Public Profile for amatsaka Find all posts by amatsaka
# 4
04-23-2002
Bit fields are like small integers. You can do everything to them that you can do to an integer including the bit-wise operators. The only exception that I can think of is that you cannot take their address.

Putting a bunch of integers into a struct would never turn that struct into an integer. The same is true for bit fields.

If you want efficient, stay away from bit fields, They are a hack to save space at the expense of execution speed. They made sense when you had small ints and limited memory.

But from your code, you don't have small ints, you have bits. If you just want to turn bits on and off and test them for being on and off, well, just do that. It's easy with the bit-wise ops. And if you turn bits on and off in an int, then you do want you wanted to do.
 Perderabo View Public Profile for Perderabo Find all posts by Perderabo

## Bitwise comparison of cols

Hello, I want to compute the bitwise number of matches in pairwise fashion for all columns. The problem is I have 18486955 rows and 750 columns. Please help with code, I believe this will take a lot of time, is there a way of tracking progress? Input Org1 Org2 Org3 A A T A ...

## Implementing operators on multiple fields

Hallo Friends, Have a look at my script: awk -F',' '\$14==9100' *_201304*.csv|wc -l > pax1; awk -F',' '\$14==9101' *_201304*.csv|wc -l >>pax1; awk -F',' '\$14==9102' *_201304*.csv|wc -l >>pax1; awk -F',' '\$14==9103' *_201304*.csv|wc -l >>pax1 I would like to include field 42. like below ...

## how to use bitwise or operator in /bin/sh

please any one can suggest me how to use bitesie || opearator to do this #initallize a=0 b=0 #condition if then a=0 else a=1 fi #bitwise or opeartion b = a || b Please view this code tag video for how to use code tags when posting code and data.

## Convert 32 bit hex value into fields in decimal

I have 32 bit value in hex that I want to separate into fields and then convert the fields into decimal values. Input file has 2 words of 32 bit hex values: 000001ac ca85210e Output both words separated into individual bit fields: ca85210e: f1(31:9), f2(8:0) f7c392ac: f1(31:14),...

## Analysis in bitwise XOR

The purpose of this article is revealing the unrevealed parts of the bitwise XOR. As we aware, the truth table for the XOR operator is : A B A^B 0 0 0 0 1 1 1 0 1 1 1 0 For example , 1^2 will be calculated as given below: First the operands...

## bitwise and between two 32 bit binaries

Hello All, i have two 16 bit binaries that in two different variables, i want to perform a bitwise AND between the two and store the result in a different variable. can anyone throw some light on doing this in a bourne shell... eg var1= 1110101010101011 ...

## bitwise and if

Hi Suppose we have these code lines: #define _IN_USE 0x001 /* set when process slot is in use */ #define _EXITING 0x002 /* set when exit is expected */ #define _REFRESHING 0x004 ... 1 main () { 2 3 unsigned r_flags =_REFRESHING; 4 5 if (r_flag &...

## Bitwise negation

I am taking an online course on Unix scripting. The topic is Unix arithmetic operators and the lesson is Logical and bitwise operations. It is not clear how much storage space Unix uses to represent integers that are typed. Bitwise negation caused me to question how many bits are used to...

## bitwise operators

can anybody write a program to divide a number by another number using bitwise operators