compare 8bit value against 16bit value

Timm

I was wondering what happens when an 8bit value is compared against a 16bit value.

I'll try to explain the problem by a code example:

bool result;
unsigned char a_8bit = 0xcd;
unsigned short b_16bit = 0xabcd;
result = a_8bit < b_16bit;

Possible results can be:

  • a_8bit is casted to unsigned short implicitly and compared to b_16bit as a 16bit value. Result is true
  • b_16bit is casted to unsigned char implicitly and compared to a_8bit as an 8bit value. Result is false

Does anybody has a clue what the compiler will do with this piece of code? Sure, i can try it out, but are there different interpretations by different compilers of this code?

masoud

1 A prvalue of an integer type other than bool, char16_t, char32_t, or wchar_t whose integer conversion rank (4.13) is less than the rank of int can be converted to a prvalue of type int if int can represent all the values of the source type; otherwise, the source prvalue can be converted to a prvalue of type unsigned int. [§ 4.5]

So, compiler can promote both of them to unsigned int and then do the comparison.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

16bit WAVE value range

From Dev

Numeric value of CMP 16bit register ,16bit register

From Dev

from 16bit unsigned value to minutes and seconds

From Dev

How to swap a 16bit Value with x86 Assembler?

From Dev

Storing unsigned long value in two 16bit register

From Dev

Convert array with 8bit value to string with char (no charcode)

From Dev

How to convert 8bit sound to 16bit

From Dev

How to write integer value "60" in 16bit binary, 32bit binary & 64bit binary

From Dev

Compare value against parameters in Drools

From Dev

How to compare a value against an array

From Dev

efficient way to convert 16 bit value to 8 bit value

From Dev

efficient way to convert 16 bit value to 8 bit value

From Dev

What's the most efficient way to compare 2 numbers (16bit) bit by bit in Python?

From Dev

Reading out a 16bit timer on an 8bit system without a latch for the high/low byte

From Dev

Converting a 16bit GeoTiff file as an 8bit JPEG file using python

From Dev

How to compare a value from UITextField against a CoreData value

From Dev

Using istream::peek() to compare next value against current value

From Dev

How to compare a value from UITextField against a CoreData value

From Dev

Create a 16bit application?

From Dev

Create a 16bit application?

From Dev

16bit to bcd conversion

From Dev

How to compare List count against single integer value?

From Dev

Compare all objects in array by value against each other

From Dev

Is it possible to compare against zero value in a generic method extending Number?

From Dev

IIS rewrite to compare Cookie Value against database list

From Dev

How to compare List count against single integer value?

From Dev

Read of Atmega8 16-bit counter always returns 8-bit value

From Dev

Getting value from a 16-bit register

From Dev

Getting value from MSB of 16 bit register

Related Related

  1. 1

    16bit WAVE value range

  2. 2

    Numeric value of CMP 16bit register ,16bit register

  3. 3

    from 16bit unsigned value to minutes and seconds

  4. 4

    How to swap a 16bit Value with x86 Assembler?

  5. 5

    Storing unsigned long value in two 16bit register

  6. 6

    Convert array with 8bit value to string with char (no charcode)

  7. 7

    How to convert 8bit sound to 16bit

  8. 8

    How to write integer value "60" in 16bit binary, 32bit binary & 64bit binary

  9. 9

    Compare value against parameters in Drools

  10. 10

    How to compare a value against an array

  11. 11

    efficient way to convert 16 bit value to 8 bit value

  12. 12

    efficient way to convert 16 bit value to 8 bit value

  13. 13

    What's the most efficient way to compare 2 numbers (16bit) bit by bit in Python?

  14. 14

    Reading out a 16bit timer on an 8bit system without a latch for the high/low byte

  15. 15

    Converting a 16bit GeoTiff file as an 8bit JPEG file using python

  16. 16

    How to compare a value from UITextField against a CoreData value

  17. 17

    Using istream::peek() to compare next value against current value

  18. 18

    How to compare a value from UITextField against a CoreData value

  19. 19

    Create a 16bit application?

  20. 20

    Create a 16bit application?

  21. 21

    16bit to bcd conversion

  22. 22

    How to compare List count against single integer value?

  23. 23

    Compare all objects in array by value against each other

  24. 24

    Is it possible to compare against zero value in a generic method extending Number?

  25. 25

    IIS rewrite to compare Cookie Value against database list

  26. 26

    How to compare List count against single integer value?

  27. 27

    Read of Atmega8 16-bit counter always returns 8-bit value

  28. 28

    Getting value from a 16-bit register

  29. 29

    Getting value from MSB of 16 bit register

HotTag

Archive