Converting Bits value into integer
-
Dear Friends. I need to convert Byte value into integer. ie. for example Input =7 1. Mark 7th Bit as 1 7 6 5 4 3 2 1 0 (8 Bit) 1 0 0 0 0 0 0 0 2. Split into 2 by 4 bit 7 6 5 4 | 3 2 1 0 (8 Bit) 1 0 0 0 | 0 0 0 0 part 1 | part 2 3. Use 8 4 2 1 logic and apply it 4. part 1 = 8 Part 2 =0 5. Output is 80
-
Dear Friends. I need to convert Byte value into integer. ie. for example Input =7 1. Mark 7th Bit as 1 7 6 5 4 3 2 1 0 (8 Bit) 1 0 0 0 0 0 0 0 2. Split into 2 by 4 bit 7 6 5 4 | 3 2 1 0 (8 Bit) 1 0 0 0 | 0 0 0 0 part 1 | part 2 3. Use 8 4 2 1 logic and apply it 4. part 1 = 8 Part 2 =0 5. Output is 80
velkumar_in wrote:
I need to convert Byte value into integer.
From what you have described it would seem you want to convert a byte to its hex value not an int (here[^])... and a byte value of 7 would not equal 10000000 it would be 00000111 which is 07 surprisingly ;)
Life goes very fast. Tomorrow, today is already yesterday.
-
Dear Friends. I need to convert Byte value into integer. ie. for example Input =7 1. Mark 7th Bit as 1 7 6 5 4 3 2 1 0 (8 Bit) 1 0 0 0 0 0 0 0 2. Split into 2 by 4 bit 7 6 5 4 | 3 2 1 0 (8 Bit) 1 0 0 0 | 0 0 0 0 part 1 | part 2 3. Use 8 4 2 1 logic and apply it 4. part 1 = 8 Part 2 =0 5. Output is 80
simple - use <<
private int ToBin(int bitNo)
{
if (bitNo >= 32)
{
throw new Exception("Too big for int32");
}
return 1 << bitNo;
}No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Dear Friends. I need to convert Byte value into integer. ie. for example Input =7 1. Mark 7th Bit as 1 7 6 5 4 3 2 1 0 (8 Bit) 1 0 0 0 0 0 0 0 2. Split into 2 by 4 bit 7 6 5 4 | 3 2 1 0 (8 Bit) 1 0 0 0 | 0 0 0 0 part 1 | part 2 3. Use 8 4 2 1 logic and apply it 4. part 1 = 8 Part 2 =0 5. Output is 80
(1< :) Luc Pattyn [[Forum Guidelines]](http://www.codeproject.com/KB/scrapbook/ForumGuidelines.aspx) [[My Articles]](http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=648011) * * * The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem. * * *