1

Working in little endian, which is excatly (including eof if there is) the bit representation of a C vector like this?

unsigned char vet[] = {0x0f, 0x05};
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
glc78
  • 439
  • 1
  • 8
  • 20

2 Answers2

2

Bit representation of a vector of unsigned chars is not dependent on endianness, because char types are single-byte, while endianness tells you how multiple bytes are arranged in memory.

Therefore, 0x0f would be found at an earlier address in memory than 0x05, producing

0000111100000101

including eof if there is [one]

Unlike C strings and arrays initialized with C strings, arrays initialized with curly brace initializers do not have an end mark.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • Ok, so i think that avery two HEX number i've got 8 bit, whatever they are, rigth? So why i've got this exercise were lenght of this vector is given by prof as 18 bit and not 24? unsigned char vet[] = { 0xBC,0xFF,0x01 }; – glc78 Aug 30 '16 at 10:55
  • 1
    @caramelleamare I have no idea how to count 18 bits in three bytes, apart from making each character 6-bit. I would definitely ask the prof where the remaining six bits are. – Sergey Kalinichenko Aug 30 '16 at 11:10
  • Infact i asked but i still recived any answer and i don't understand how to procede with the exercise! And nowhere is written to consider char as 6-bit long. The exercise asks me to find min and max subsequence of 0 bit in that given vector. – glc78 Aug 30 '16 at 11:45
  • 1
    @caramelleamare min is 1, max is 7 regardless of how you order the vector (front to back or back to front). – Sergey Kalinichenko Aug 30 '16 at 12:23
  • 7?! Isn't max 5? However still remains mistery about the length. – glc78 Aug 30 '16 at 14:26
  • 1
    @caramelleamare I am talking about your other example, `BC,FF,01`, with seven consecutive zeros in the representation of `0x01`. – Sergey Kalinichenko Aug 30 '16 at 14:29
  • Prof says "If len is minor then a multipe of 8, it means that bits of last byte are not totally used". – glc78 Aug 30 '16 at 15:59
  • @caramelleamare That wouldn't make `BC,FF,01` count 18, though: it could be 22 if `BC` is the last byte, but that's about it. Chopping off the initial unused bits along with the trailing ones would produce 15. – Sergey Kalinichenko Aug 30 '16 at 16:07
  • Couldn't be `0x01` the last byte represented with bits `01`? So it could be 8+8+2 without chopping. – glc78 Aug 30 '16 at 16:14
  • 1
    @caramelleamare Hex `01` is binary `00000001`, so zeros are in the middle, and cannot be dropped. – Sergey Kalinichenko Aug 30 '16 at 16:23
  • Right, but why you say that `BC` is the last byte and not `01`? – glc78 Aug 30 '16 at 16:35
  • @caramelleamare I tried it both ways to see if we could "back into" prof's solution by ordering the bytes in some other way, but it does not produce 18 no matter how you order the bytes. – Sergey Kalinichenko Aug 30 '16 at 16:40
  • Ok, i asked him, let's see. Maybe also that the last byte is `01` truncated after the first two bit `00` – glc78 Aug 30 '16 at 16:44
0

Well, so if vector is:

unsigned char vet[] = { 0xBC,0xFF,0x01 }

Bit representation should be:

101111001111111100000001

And its length is 24 bit because there is no end mark, rigth?

glc78
  • 439
  • 1
  • 8
  • 20