Hi
I have never deal with C# before ,,, That is why my question will look silly :crying:
I have this code from the web:
byte waveByte = waveBuffer;
now I don't now how C# deals with byte ,,,
what I want to do is change one bit from wave Byte
example :
waveByte =16=10000
then I want to change the red bit to 1
=10000 = 10100
HOW???
Thank you so much
8 replies to this topic
#1
Posted 17 August 2010 - 06:05 AM
|
|
|
#2
Posted 17 August 2010 - 06:27 AM
:crying::crying::crying::crying::crying::crying:
#3
Posted 17 August 2010 - 08:28 AM
pleaaaaaaaase anyone....
may be I can convert it to string first -----> change that bit ----------> convert it back to byte ????
is this will work???
help please
may be I can convert it to string first -----> change that bit ----------> convert it back to byte ????
is this will work???
help please
#4
Posted 17 August 2010 - 02:06 PM
prof.deedee said:
waveByte =16=10000
then I want to change the red bit to 1
=10000 = 10100
then I want to change the red bit to 1
=10000 = 10100
byte waveByte = 16; waveByte = (byte)(waveByte | 4); // waveByte = 20 (bin: 10100)
Or.... I wrote simple method for this:
static byte ChangeBit(byte source, byte bitNumber, byte value)
{
if (bitNumber > 8 || (value != 0 && value != 1))
throw new ApplicationException("Invalid arguments");
bitNumber = (byte)(Math.Pow(2, bitNumber));
if (value == 0)
return (byte)(source & ~bitNumber);
else
return (byte) (source | bitNumber);
},where:
source - old value,
bitNumber - number of bit (starts from 0), for your example is 2
value - target value for bit (0 or 1)
Using:
byte waveByte = 16; waveByte = ChangeBit(waveByte, 2, 0); // waveByte = 20 (bin: 10100)
Sorry for my beginner's English.
#5
Posted 17 August 2010 - 02:42 PM
Thank you soo much
#6
Posted 17 August 2010 - 02:44 PM
can I change it to String ---->change the bit ------>change it back to byte????
#7
Posted 29 August 2010 - 02:36 PM
sorry NightmareZ what this line suppose to do:
and this one:
Quote
(byte)(source & ~bitNumber);
and this one:
Quote
(byte) (source | bitNumber);
#8
Posted 01 September 2010 - 08:51 AM
why change it to a string? All you have to do is use the | (or) operator to change the bit or byte from 0 to 1
int n = 10000; int mask = 100; n = n | mask; // or you could do this n = n | 100;
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#9
Posted 02 September 2010 - 08:16 AM
Thank you that is really work
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









