How to enumerate the position of a bit within a byte?

1

Where to start putting an ordinal number in a given byte, do I start counting the most significant (left) or least significant (right)?

For example for the decimal number 128 that has the binary representation:

1000 0000

If I want to refer to the eighth byte bit, who is the relevant digit? 1 or 0?

Would it be A-mode or B-mode? Mode A
1000 0000
8765 4321

Mode B
1000 0000
1234 5678

    
asked by anonymous 12.06.2017 / 17:01

1 answer

1

The A mode would be the correct one.

Ignore the name bit - A binary value is represented in the same way as a decimal value: In an integer the higher value positions are located to the left, since new positions are added when the previous position suffers overflow :

    8 + 1  // 9:     Uma casa decimal
    9 + 1  // 10:    Não pode ser contido em apenas uma posição,
   10      //        casa decimal 2 recebe o valor em overflow.
  ...
   98 + 1  // 99:    Duas casas decimais
   99 + 1  // 100:   Não pode ser contido em apenas duas posições, 
  100      //        casa decimal 3 recebe o valor em overflow.

So:

128 = 100 + 20 + 8

In the above example we can say that the position (house) 3 has the value 1 , which means 100 in decimal.

In binary the value

1000 0000

It has the value 1 in the 8 position, which also means 128 (2 to 7th power).

    
12.06.2017 / 17:28