473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can you do this? (bit ops)


Hello Group,

With all the different threads lately about bit operations, I'm
wondering if you can do this:

typedef unsigned long uint32

uint32 eof;
uint32 bmap;
uint32 blocksect;
uint32 sectsize;
uint32 i;
....
blocksect = 4;
sectsize = 512;
bmap = usbdev.fcb[x].inode.bitmap;
....
for (i = 0; i < blocksect; i++)
eof += (((bmap <<= 1 & 0x80000000) != 0) ? 1 : 0) * sectsize;
....


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Apr 4 '07 #1
3 1396

"Daniel Rudy" <sp******@spamthis.netwrote in message
news:lw*****************@newssvr21.news.prodigy.ne t...
>
Hello Group,

With all the different threads lately about bit operations, I'm
wondering if you can do this:

typedef unsigned long uint32

uint32 eof;
uint32 bmap;
uint32 blocksect;
uint32 sectsize;
uint32 i;
...
blocksect = 4;
sectsize = 512;
bmap = usbdev.fcb[x].inode.bitmap;
...
for (i = 0; i < blocksect; i++)
eof += (((bmap <<= 1 & 0x80000000) != 0) ? 1 : 0) * sectsize;
...
You can do it, but it probably isn't what you want.
This will & 1 with 0x80000000 and then shift bmap the 0 bits
yielded from that &. I am guessing you want:

eof += ((((bmap <<= 1) & 0x80000000) != 0) ? 1 : 0) * sectsize;

Apr 4 '07 #2
At about the time of 4/4/2007 3:51 AM, Barry stated the following:
"Daniel Rudy" <sp******@spamthis.netwrote in message
news:lw*****************@newssvr21.news.prodigy.ne t...
>Hello Group,

With all the different threads lately about bit operations, I'm
wondering if you can do this:

typedef unsigned long uint32

uint32 eof;
uint32 bmap;
uint32 blocksect;
uint32 sectsize;
uint32 i;
...
blocksect = 4;
sectsize = 512;
bmap = usbdev.fcb[x].inode.bitmap;
...
for (i = 0; i < blocksect; i++)
eof += (((bmap <<= 1 & 0x80000000) != 0) ? 1 : 0) * sectsize;
...
You can do it, but it probably isn't what you want.
This will & 1 with 0x80000000 and then shift bmap the 0 bits
yielded from that &. I am guessing you want:

eof += ((((bmap <<= 1) & 0x80000000) != 0) ? 1 : 0) * sectsize;
Good eye.

Here's the entire function that has that line in it...

/* computes the file EOF from the inode data */
static uint32 fs_inode_ceof(int fd)
{
uint32 i; /* generic counter */
uint32 eof; /* end of file pointer (file size in bytes) */
uint32 blocksize; /* size of disk block (in bytes) */
bmap_t bmap; /* sector bitmap (eof block fragment map) */

eof = 0;
blocksize = usbdev.sect_block * usbdev.sect_size;
bmap = usbdev.fcb[fd].inode.bitmap;
for (i = 0; i < FS_MAXFRAG; i++)
{
eof += usbdev.fcb[fd].inode.loc[i].length * blocksize;
}
if (bmap != 0)
{
eof -= blocksize;
for (i = 0; i < usbdev.sect_block; i++)
{
eof += ((((bmap <<= 1) & FS_BITMASK) == 0) ? 0 : 1) *
usbdev.sect_size;
}
eof += usbdev.fcb[fd].inode.mod;
}
return(eof);
}


--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Apr 4 '07 #3
On Apr 4, 9:49 pm, Daniel Rudy <spamt...@spamthis.netwrote:
>
With all the different threads lately about bit operations, I'm
wondering if you can do this:

for (i = 0; i < blocksect; i++)
eof += (((bmap <<= 1 & 0x80000000) != 0) ? 1 : 0) * sectsize;
I'm guessing you want (bmap <<= 1). Also, get rid of the redundant
use of the ternary operator. You could optionally replace !=0 with !!
which I think is a little clearer in this case. The line would be:

eof += sectsize * (0 != ((bmap <<= 1) & 0x80000000));
or
eof += sectsize * !!((bmap <<= 1) & 0x80000000);

Now, you *can* write it this way, but it would be a lot less
confusing to readers (and to yourself!) if you wrote it this way:

for (i = 0; i < blocksect; ++i, bmap <<= 1)
{
if (bmap & 0x40000000)
eof += sectsize;
}

Apr 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Matthew Wilson | last post by:
I'm playing around with genetic algorithms and I want to write a function that mutates an integer by iterating across the bits, and about 1 in 10 times, it should switch a zero to a one, or a one...
24
by: ad | last post by:
Use a variable of char type and each bit of it indicates if a button is pressed or not. For example, 0010010 tells that 3rd and 7th buttons are pressed down. How to set bit to to 1 or 0 in...
112
by: Carsten Hansen | last post by:
Suppose I'm using an implementation where an int is 16 bits. In the program below, what function is called in the first case, and what is called in the second case? Also, if there is a difference...
12
by: Eric Lilja | last post by:
Hello, I'm trying to help someone on a linux-oriented forum. I've taken his original code and cleaned it up, but I am still wondering about something. Here's the code: #include <stdio.h> int...
6
by: Hameed U. Khan | last post by:
Hi I've started learning C++. I want to know is there any better way of solving the problem defined below or how can I improve the bitwise operations. If there is any other method using bitwise...
19
by: David W | last post by:
float nanometers(long pm) { return pm / 1000.0f; } void f() { if(nanometers(309311L) == nanometers(309311L)) { // do something }
15
by: Chris | last post by:
This is just some dummy code to mimic what's being done in the real code. The actual code is python which is used as a scripting language in a third party app. The data structure returned by the...
4
by: Eric Lilja | last post by:
Hello! Consider this code: const char ops = {'*', '/', '+', '-'};//, '(', ')' }; const int input_prio = { 3, 3, 1, 1 };//, 100, 0 }; const int stack_prio = { 4, 4, 2, 2...
5
by: copx | last post by:
How portable are direct bit operations? Which ones are portable? I have never bothered learning such low-level stuff (I have an excuse: I am not a professional programmer), so I really don't know....
32
by: .rhavin grobert | last post by:
guess you have a processor that can handle 32bit natively and you have a 32-bit-int. im now looking for some *ultrafast* way to determine if an int has more than one bit set. any ideas?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.