Byte conversion from 32 bit to 8 bit

Anil Gadiyar

hi this I want to send this hex vales but i am getting error.. I am send byte values ,** my error.. constant vales cannot be converted to byte.**

class constant(){
public const byte MESSAGE_START = 0x1020; // command hex
}


public override IEnumerable<byte> ToBytes()
        {
      yield return constant.MESSAGE_START ;

    }

HI, there is another twist i am facing, though with your help I passed the hex value, I should decimal equivalent when i pass through the below method, but value I get is 16.

protected override void TransmitCommand(Device device, Command command) { int count = 0;

        foreach (var b in command.ToBytes())
            transmitBuffer[count++] = b;   // values i get is 16 but not decimal values 4128
    }
Richard Schneider

As I said in the comment, the value MESSAGE_START is a short not a byte. Try this

class constant() {
  public const short MESSAGE_START = 0x1020; // command hex
}

public override IEnumerable<byte> ToBytes()
{
  yield return (byte) (constant.MESSAGE_START >> 8);
  yield return (byte) (constant.MESSAGE_START & 0xff);
}

The above code assumes that the byte representation of the value is in network byte order (most significant byte first). For LSB do

public override IEnumerable<byte> ToBytes()
{
  yield return (byte) (constant.MESSAGE_START & 0xFF);
  yield return (byte) (constant.MESSAGE_START >> 8);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does PNG bit-depth conversion from 8-bit to 32-bit increase quality?

From Dev

Conversion from 32 bit binary string to int Java

From Dev

32 bit registers act as 8 bit ones

From Dev

32-bit Hamming String formation from 32 8-bit comparisons

From Dev

Migrating from 64 bit to 32 bit

From Dev

moving from ubuntu 32 bit to 64 bit

From Dev

going from 32 bit to 64 bit in assembly

From Dev

moving from ubuntu 32 bit to 64 bit

From Java

How to create a 32-bit integer from eight (8) 4-bit integers?

From Dev

Copying serialized struct from an 8-bit system to a 32-bit system

From Dev

C++ 32 bit integer from file to 8 bit character to file - program crashing at certain integer

From Dev

24- to 32-bit conversion in Java

From Dev

C code 32 to 64 bit type conversion

From Dev

Why is the default alignment for `int64_t` 8 byte on 32 bit x86 architecture?

From Dev

What's the algorithm to translate 8 byte memory into a double number on x86 32bit?

From Dev

String to Bool Conversion ... works in 4 bit but not 8 bit

From Dev

Byte array to an 8 bit truecolor image

From Dev

Hexadecimal: Set an 8-bit byte in an int

From Dev

Is it safe to read and write on an array of 32 bit data byte by byte?

From Dev

Multiplication of two 32 bit numbers using only 8 bit numbers

From Dev

NumPy convert 8-bit to 16/32-bit image

From Dev

Converting 8 bit PNG to 32- bit with alpha

From Dev

C, Creating a 32 bit pointer to a 8 bit array

From Dev

Install 32 bit ubuntu along side 64 bit windows 8

From Dev

Install 32 bit ubuntu along side 64 bit windows 8

From Dev

Working with 32 bit data types and 8 bit data type in ARM

From Dev

Convert a 8bit list to a 32 bit integer array in python

From Dev

8 bit int vs 32 bit int on a 32 bit architechture (GCC)

From Dev

C - How to check if 8 bits are in 32 bit?

Related Related

  1. 1

    Does PNG bit-depth conversion from 8-bit to 32-bit increase quality?

  2. 2

    Conversion from 32 bit binary string to int Java

  3. 3

    32 bit registers act as 8 bit ones

  4. 4

    32-bit Hamming String formation from 32 8-bit comparisons

  5. 5

    Migrating from 64 bit to 32 bit

  6. 6

    moving from ubuntu 32 bit to 64 bit

  7. 7

    going from 32 bit to 64 bit in assembly

  8. 8

    moving from ubuntu 32 bit to 64 bit

  9. 9

    How to create a 32-bit integer from eight (8) 4-bit integers?

  10. 10

    Copying serialized struct from an 8-bit system to a 32-bit system

  11. 11

    C++ 32 bit integer from file to 8 bit character to file - program crashing at certain integer

  12. 12

    24- to 32-bit conversion in Java

  13. 13

    C code 32 to 64 bit type conversion

  14. 14

    Why is the default alignment for `int64_t` 8 byte on 32 bit x86 architecture?

  15. 15

    What's the algorithm to translate 8 byte memory into a double number on x86 32bit?

  16. 16

    String to Bool Conversion ... works in 4 bit but not 8 bit

  17. 17

    Byte array to an 8 bit truecolor image

  18. 18

    Hexadecimal: Set an 8-bit byte in an int

  19. 19

    Is it safe to read and write on an array of 32 bit data byte by byte?

  20. 20

    Multiplication of two 32 bit numbers using only 8 bit numbers

  21. 21

    NumPy convert 8-bit to 16/32-bit image

  22. 22

    Converting 8 bit PNG to 32- bit with alpha

  23. 23

    C, Creating a 32 bit pointer to a 8 bit array

  24. 24

    Install 32 bit ubuntu along side 64 bit windows 8

  25. 25

    Install 32 bit ubuntu along side 64 bit windows 8

  26. 26

    Working with 32 bit data types and 8 bit data type in ARM

  27. 27

    Convert a 8bit list to a 32 bit integer array in python

  28. 28

    8 bit int vs 32 bit int on a 32 bit architechture (GCC)

  29. 29

    C - How to check if 8 bits are in 32 bit?

HotTag

Archive