shift « bit « C Data Type Q&A

Home
C Data Type Q&A
1.binary
2.bit
3.byte
4.char
5.character
6.decimal
7.Development
8.float
9.hex
10.integer
11.prime
12.random
13.struct
C Data Type Q&A » bit » shift 

1. Where can I find a bit shifting guide for C?    stackoverflow.com

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 ...

2. (-1 >> 1) == -1 - Why?    stackoverflow.com

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 ...

3. What does this line of code do?    stackoverflow.com

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 ...

4. Bit shifting in internet checksums    stackoverflow.com

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, ...

5. shifting right / what I am doing wrong?    stackoverflow.com

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 ...

6. circular shift c    stackoverflow.com

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 ...

7. Bit Twiddling Hacks: interleave bits the obvious way    stackoverflow.com

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 ...

8. How do I shift out bits in C?    stackoverflow.com

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 ...

9. Logical, arithmetical bitwise shifts    stackoverflow.com

Seeking to clarify something. It is my understanding that with regard to arithmetical, logical bitwise shifts:

  1. << work the same for both
  2. >> shifts differ in which logical shift will always pad byte with ...

10. bit shifting in C    stackoverflow.com

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 ...

11. Arithmetic Bit-shift on a signed integer    stackoverflow.com

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 ...

12. Way to represent a top 10 list with tie breakers as a single numerical value    stackoverflow.com

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 ...

13. Bit shifting in C    stackoverflow.com

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 |= ...

14. Implementing Logical Right Shift in C    stackoverflow.com

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); // ...

15. Shift right ">>" in C99    stackoverflow.com

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 ...

16. shift left bits value in c    stackoverflow.com

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 ...

17. Algorithmic efficiency in selecting based on bits    stackoverflow.com

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 ...

18. bit shift different result in similar programs    stackoverflow.com

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 ...

19. c standard and bitshifts    stackoverflow.com

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 << ...

20. representing 2 numbers in 8 bits    stackoverflow.com

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 ...

21. More bit shifting issues    bytes.com

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 ...

22. Bit Shifting problem with endieness    bytes.com

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 ...

24. bit shifting as lvalue    bytes.com

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 ...

25. Bit Shifting Question    bytes.com

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 ...

26. Bit shifting vs Bitfields    bytes.com

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 ...

27. Shift all '1' bits in a number to the left end    cboard.cprogramming.com

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 ...

28. Help with shifting blocks( 24-bit BMP image    cboard.cprogramming.com

29. Bit SHIFT ISSUES    cboard.cprogramming.com

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 ...

30. C how to Shift bits in BCD    cboard.cprogramming.com

31. Bit shift    cboard.cprogramming.com

32. anyone help with this shift bit question    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 ...

33. Bit Shifting question (simple)    cboard.cprogramming.com

34. Quick question regardin bit shifting    cboard.cprogramming.com

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; }

35. Bit Shifting Question    cboard.cprogramming.com

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

37. Bit shifting with matrices    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.com

I'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

40. Help With BIT SHIFTING    forums.devshed.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

41. Question regarding logical bit shifting    forums.devshed.com

42. Bit Shift Problem    forums.devshed.com

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 ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.