Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Converting Bits value into integer

Converting Bits value into integer

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    velkumar_in
    wrote on last edited by
    #1

    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

    M OriginalGriffO L 3 Replies Last reply
    0
    • V velkumar_in

      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

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • V velkumar_in

        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

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        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

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • V velkumar_in

          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

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups