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. Getting a - "Cannot implicitly convert type 'int' to 'byte'" error - Help!

Getting a - "Cannot implicitly convert type 'int' to 'byte'" error - Help!

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 3 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.
  • L Offline
    L Offline
    link_79
    wrote on last edited by
    #1

    Hi everybody, this is my first post so please bear with me. Ok here's what I am trying to do, and for the love of me I can't 'see' an implicit conversion happenning, so why the hell is the compiler whining??? here is a class skeleton, similar to what I have public class X { protected void ThisIsKillingMe(byte[] oldABC) { byte[] newABC = new byte[100]; // line below reports an implicit complier error newABC[i] = oldABC[p] ^ xyz[q]; } private static readonly byte[] xyz = {0x12, 0x5F, ....}; } Thanks for any and all help.

    A L 2 Replies Last reply
    0
    • L link_79

      Hi everybody, this is my first post so please bear with me. Ok here's what I am trying to do, and for the love of me I can't 'see' an implicit conversion happenning, so why the hell is the compiler whining??? here is a class skeleton, similar to what I have public class X { protected void ThisIsKillingMe(byte[] oldABC) { byte[] newABC = new byte[100]; // line below reports an implicit complier error newABC[i] = oldABC[p] ^ xyz[q]; } private static readonly byte[] xyz = {0x12, 0x5F, ....}; } Thanks for any and all help.

      A Offline
      A Offline
      Andrew McCarter
      wrote on last edited by
      #2

      I'm presuming that when you perform the ^ on the two byte data types (which are Integers, btw), the compiler performs an implicit conversion to Integer. You are then trying to assign the resultant integer value to the newly declared byte array. You probably need to cast the result back to byte. Or I could be totally full of it :-O

      L 1 Reply Last reply
      0
      • A Andrew McCarter

        I'm presuming that when you perform the ^ on the two byte data types (which are Integers, btw), the compiler performs an implicit conversion to Integer. You are then trying to assign the resultant integer value to the newly declared byte array. You probably need to cast the result back to byte. Or I could be totally full of it :-O

        L Offline
        L Offline
        link_79
        wrote on last edited by
        #3

        You are the Man. Thanks so much, doing this worked - newABC[i] = BitConverter.GetBytes(oldABC[p] ^ xyz[q])[0];

        1 Reply Last reply
        0
        • L link_79

          Hi everybody, this is my first post so please bear with me. Ok here's what I am trying to do, and for the love of me I can't 'see' an implicit conversion happenning, so why the hell is the compiler whining??? here is a class skeleton, similar to what I have public class X { protected void ThisIsKillingMe(byte[] oldABC) { byte[] newABC = new byte[100]; // line below reports an implicit complier error newABC[i] = oldABC[p] ^ xyz[q]; } private static readonly byte[] xyz = {0x12, 0x5F, ....}; } Thanks for any and all help.

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          newABC[i] = (byte)(oldABC[p] ^ xyz[q]); top secret xacc-ide 0.0.1

          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