Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here you need to note down two things</p> <ul> <li>How the characters are stored </li> <li>Endianess of the system</li> </ul> <p>Each characters (Alphabhets, numbers or special characters) are stored as 7 bit ASCII values. While doing <code>memcpy</code> of the string(array of characters) "0006" to a 4bytes int variable, we have to give address of string as source and address of int as destination like below.</p> <pre><code>char a[] = "0006"; int b = 0, c = 6; memcpy(&amp;b, a, 4); </code></pre> <p>Values of a and b are stored as below.</p> <pre><code>a 00110110 00110000 00110000 00110000 b 00000000 00000000 00000000 00000000 c 00000000 00000000 00000000 00000110 MSB LSB </code></pre> <p>Because ASCII value of <code>0</code> character is 48 and <code>6</code> character is 54. Now <code>memcpy</code> will try to copy whatever value present in the <code>a</code> to <code>b</code>. After <code>memcpy</code> value of b will be as below</p> <pre><code>a 00110110 00110000 00110000 00110000 b 00110110 00110000 00110000 00110000 c 00000000 00000000 00000000 00000110 MSB LSB </code></pre> <p>Next is endianess. Now consider we are keeping the value <code>0006</code> to the character buffer in some other way like <code>a[0] = 0; a[1] = 0; a[2]=0; a[3] = 6;</code> now if we do <code>memcpy</code>, we will the get the value as 100663296(<code>0x6000000</code>) not 6 if it is little endian machine. In big endian machine you will get the value as <code>6</code> only.</p> <pre><code>c 00000110 00000000 00000000 00000000 b 00000110 00000000 00000000 00000000 c 00000000 00000000 00000000 00000110 MSB LSB </code></pre> <p>So these two problems we need to consider while writing a function which converts number charters to integer value. Simple solution for these problem is to make use of existing system api <code>atoi</code>. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload