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. C# - Binary Operations?

C# - Binary Operations?

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
2 Posts 2 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.
  • W Offline
    W Offline
    wbjohnson
    wrote on last edited by
    #1

    Hi all! Having some trouble with converting this logic into some nice C# code! can anyone help?? 1. Get the "twos complement" of a number (invert, add 1) 2. Get the LSB of that result... Example with: 1506 1506 = 10111100010 Invert = 01000011101 Add 1 = 01000011110 2*LSB = 00011110 Result = 00011110 (or 1E in hex) Can anyone point me in the right direction to get these results in C# please!

    H 1 Reply Last reply
    0
    • W wbjohnson

      Hi all! Having some trouble with converting this logic into some nice C# code! can anyone help?? 1. Get the "twos complement" of a number (invert, add 1) 2. Get the LSB of that result... Example with: 1506 1506 = 10111100010 Invert = 01000011101 Add 1 = 01000011110 2*LSB = 00011110 Result = 00011110 (or 1E in hex) Can anyone point me in the right direction to get these results in C# please!

      H Offline
      H Offline
      H M J
      wrote on last edited by
      #2

      int val = 1506; int result = (~val + 1) & 0X000000FF;

      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