How much memory 32 bit takes to store single char ?

Thread Starter

John99407

Joined Jul 12, 2019
77
Hi guys

I have one question, single char take one byte of memory. when we are sending one char 'X' from 32 bit micro to 64 bit Desktop PC. Micro is 32 bit and its 32 bit wide data register so when we store one char value that is 8 bit on 32 bit register of micro so we are wasting 3 bytes memory location ?

1586431747784.png
 

jpanhalt

Joined Jan 18, 2008
11,087
One way is the waste register space as you suggest.

However, the transmission protocol you are using may dictate 8-bit transfers. In that case, one way to address your question is to assume you have four, 7-bit ascii characters packed into a 32-bit register. You can send one character at a time by rotating the bits from the register. You can also use masking to extract 8-bit bytes and send them.

If you can send a full 32-bits at a time, you can still pack characters in that byte.
 

MrChips

Joined Oct 2, 2009
27,711
In general, 32-bit and 64-bit processors can access data in smaller chunks, such as 1, 8, and 16-bit chunks.
Even if the register is 16, 32, or 64-bits wide, 8-bits of data is transmitted as 8-bits. The whole register is not transmitted.
With regards to memory, data can still be stored one byte at a time. Four bytes can be stored into one 32-bit location.
Note that Unicode has different standards which can have 1 to 4 bytes.

In summary, the answer is no, 3 bytes of memory are not wasted.
 
Top