I have looked at http://stackoverflow.com/questions/141525/absolute-beginners-guide-to-bit-shifting but I still find the concept of bit shifting difficult to understand.
Can someone point me in the direction of a more basic guide to bit ... |
Why does (-1 >> 1) result in -1? I'm working in C, though I don't think that should matter.
I can not figure out what I'm missing...
Here is an example of a ... |
Confused as to what this code does
for (L=0; L < levels; L++, N_half>>=1){
func( y, N_half);
} // end: levels for loop
In particular this " N_half>>=1 "
Thanks
... |
This is almost certainly a very silly question, but for some reason I'm having trouble with internet checksum calculations. All of the algorithms basically look something like this:
WORD chksm(WORD *startpos, ...
|
Does not work as expected becuase it does not set the MSB bit correct.
I am using metrowerks compiler.
//shifting right 5 characters
char * buffer;
buffer=global_buffer;
for(i=0;i<5;i++) //shift right for 1;
{
buffer[17-i]=(buffer[17-i]>>1)|(buffer[17-i-1]<<7);
}
EDIT
input ... |
I have to shift the int one place to the right and return it
In Java i can just return n >> 1;
Is this possible in C?
The method we were given is ... |
i am interested on this problem
Interleave bits the obvious way
(from http://graphics.stanford.edu/~seander/bithacks.html)
unsigned short x; // Interleave bits of x and y, so ...
|
|
I am trying to write a function in C that will shift out the individual bits of a byte based on a clock signal. So far I have come up with ... |
Seeking to clarify something.
It is my understanding that with regard to arithmetical, logical bitwise shifts:
- << work the same for both
- >> shifts differ in which logical shift will always pad byte with ...
|
int x = 2;
x = rotateInt('L', x, 1); // should return 4
x = rotateInt('R', x, 3); // should return 64
Here is the code, can someone check it and let me know ... |
I am trying to figure out how exactly arithmetic bit-shift operators work in C, and how it will effect signed 32 bit integer.
To make things simple, lets say we work within ... |
I have a top 10 list with a score (highest score wins) and a timestamp.
The timestamp is used in the case of a tie score, in which case the tied score ... |
How would I do the following:
unsigned short x = 0xFFFF;
unsigned short y = 0xAE;
x |= y & 1;
x |= y & (1 << 1);
x |= y & (1 << 2);
x |= ...
|
I'm working on making a logical right shift function in C using only bitwise operators. Here's what I have:
int logical_right_shift(int x, int n)
{
int size = sizeof(int); // ...
|
Possible Duplicate:
Weird behavior of right shift operator
Hello
Why both numbers from this function are printed the same? It is not a cyclic shift.
unsigned int i=0x89878685;
int ...
|
update
I'm new at hardware programming with c compiler for the PIC 18F4550 from Microchip.
My question is, can someone give me an example 'how to shift bits left with a carry' 1110 ... |
I was wondering what your ideas were in developing an efficient algorithm for doing if/else switch/cases based on bits. I have 8 bits to play with and I need to divide ... |
Here is one program
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned char a=0x80;
printf("%d\n",a<<1);
}
The output of above is 256
Now here is one more version of above program
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned char a=0x80;
a=a<<1;
printf("%d\n",a);
}
The output of ... |
This question was first inspired by the (unexpected) results of this code:
uint16_t t16 = 0;
uint8_t t8 = 0x80;
uint8_t t8_res;
t16 = (t8 << ...
|
I have 2 sets of values. Each is in the range of -50 to + 50.
Is there any way to represent two of these values in a single byte?
(I ... |
Boltar wrote: > I seem to be having yet more wierd issue with bit shifting. It seems the following code doesnt do anything under gcc (ie it returns -1 as both results). Anyone know why? Is it another language definition or CPU issue? > main() { printf("%d\n",(int)0xFFFFFFFF >1); printf("%d\n",(int)-1 >1); } Shift-right of negative values is implementation-defined; you're likely to get ... |
I am having the following problem of bit shifting. My program runs on a little endian machine. Consider that if I have the following data represented in big endian... 0x12345678 the little endian representation would be 0x78563412. Now if I wan to shift my original data by 4 bits to 0x01234567, then my approach would be val = 0x12345678 htonl(htonl(val)>>4) and ... |
|
P: n/a jcitrix@gmail.com Hi folks, I'm looking at a problem that has been bugging me for a few days. It's an forum question/problem that was posted by a reader and I can't get my head around it. I've tried my due diligence to look this up myself, but without knowing what the beast is I can't seem to form the right ... |
johnno Is anyone able to help me here? I have the following VB code and wish to have it rewritten in C++ but unsure how. Any help would be greatly appreciated. Effectively the code is packing a 10 letter word into 60 bits. I only need to deal with 64 valid values. ie the values 90 - 64gv so the first ... |
Hello All, I am writing an application which receives a word which is a bitmap. I have created a word typedef which contains a bitfield defining each bit. however, I was wondering however if it would be better to write a macro to access each bit instead of the bitfield. I have read the C-FAQ on bit fields, but was wondering ... |
Hello, I'm working on Practical C Programming exercise 11-6 and have a solution. I just feel like it's kind of messy, so I wanted to see if others had feedback on a cleaner, easier way. Mind you, we haven't reach pointers yet in the book. Thanks! Code: /************************************************************* pcp11_6 -- Takes the 1 bits in a number and shifts them to ... |
|
Hi there, I am just looking for some advice on Bit shifting. I have a program that will split a 32bit into its 4 bytes. This works to a certain extent: I get the following when i run the snippet of code below: Original HEX NUMBER: CD53BB10; BYTE1: CD BYTE2 : 53 BYTE3: BB BYTE4: 1 Code: #include #include ... |
|
31. Bit shift cboard.cprogramming.com |
I cannot see the logic here, really... If I enter 1 the most significan bit will be the first one... And you want to change all other bits to 1 and converting my input to -1? Why? If you want to give the possibility to enter 8-bit value and unsigned and then convert it to 8-bit signed value - use char ... |
|
itsme@itsme:~/C$ ./shift 10000111 - 87 00001110 - 0E itsme@itsme:~/C$ cat shift.c #include void show_it(int num) { int i; for(i = 7;i >= 0;--i) printf("%c", (num >> i) & 1 ? '1' : '0'); printf(" - %02X\n", num); } int main(void) { unsigned char num = 0x87; show_it(num); num <<= 1; show_it(num); return 0; } |
Shifting right one positon is often used to divide a number by two. That is why when shifting right negative numbers the MSB is filled with 1 to get the right result. Alwais thought that this is what should happen with standard conforming compilers but hammer pointed out that this is implementation-defined. Try this: Code: #include #include using namespace ... |
36. Shifting Bits cboard.cprogramming.com |
No. It doesn't shift the array. It simply finds whatever value is at "snake[0][0]" and shifts it. You could always do something like a double linked list, with a pointer to the head and tail, and just pop the end off and add a new head. Then you just change whatever position is stored in the "tail" back to a space. ... |
38. bit shifting cboard.cprogramming.comI've written a bunch of stuff for work - this is extracted and simplified - also slower. It takes a loooong bitstream and shifts all the bits in it. To show you what's going on I copied in some other routines which is why the globals and mangled names. you can modify it as you see fit. Code: /* xbit.c bitshift ... |
39. bit shifting cboard.cprogramming.com |
I am currently working on a program due tonight!!! Anyways i was wondering, because i have to output a truth table, how to extend 0 to 000 based on the number of inputs...i know its >> to bit shift but first i have to get it to output 000 thanks in advance |
|
I have a bit of a problem with this code. I am dealing with 32 bit messages and on of the fields within this message is 21 bits long. It also scaled to provide a range of -180 to + 180; i.e. LSB = 0.000172. I have for each field its mask for the message; i.e. in this case 0x1FFFFF00. Also ... |