![]() |
| ||
| bitwise operations in C 1 Attachment(s) Hello :) i need to write a program which gets from user number and index ( 0 <= number <= 255 , 0<=index<=7) . then to add up to the number in bitwise a 1 in the place of the index : if number is 102 which is 01100110 and index is 4 which is 01110110 and get 118 as a result. for some reason it doesnt do that ..... i have no idea why , i used OR operation between numbers ..... :rolleyes: Code added thanx , Yotam |
| ||
| Re: bitwise operations in C 102 (decimal) = 1100110 (binary) 1 left shifted 4 is 10000 (binary) 1100110 (binary)If I understand you. #include <stdio.h> |
| ||
| Re: bitwise operations in C that code is actually adding 1 in place of index ? |
| ||
| Re: bitwise operations in C |
| ||
| Re: bitwise operations in C ch2=pow(2,index + 1);Why did you add 1 to the index? - 32 (2^5) in binary is 00100000 - The code would give your expected result without that. |
| All times are GMT -4. The time now is 9:21 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC