Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint Hex number as decimal
    primarykey
    data
    text
    <p>I'm trying to make fdisk program in Linux. I have a buffer which contains the partition disk information(starting sector- ending sector- size of partition...etc).</p> <p>The problem that I have buffer array <code>char buf[512]</code> and that buffer contains the needed info and I want to print it in decimal. The result should be <code>dec 2048</code> but my program print <code>hex 0800</code> </p> <p>The program can see each digit eight zero zero and I want it to see eight hundreds.</p> <hr> <h2>The Code</h2> <pre><code>#define _LARGEFILE64_SOURCE #define buff_SIZE 512 #include &lt;sys/types.h&gt; #include &lt;sys/stat.h&gt; #include &lt;fcntl.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;errno.h&gt; #include &lt;unistd.h&gt; int main(int argc, char ** argv){ int fd; // File descriptor unsigned char buf[buff_SIZE]; if(argc&lt;2) { perror("Error: No such file or directory"); exit(2); // File scripted: 0 input 1 output 2 error } // Open Driver:: if((fd=open(argv[1], O_RDONLY | O_LARGEFILE ))==-1){ perror("Error: Can not open the file"); exit(2); } // Reading file descriptor into buffer:: if(read(fd, buf, buff_SIZE)!=buff_SIZE) perror("Error: Reading error"); if ((buf[446]==0x80)||(buf[446]==0x00)) printf("%x\n",buf[446]); int i; for(i=447;i&lt;=449;i++) printf("%x\n",buf[i]); printf("Partation ID:%x\n",buf[450]); printf("Starting Sector:%x%x%x%x\n",buf[454],buf[455],buf[456],buf[457]); //***THE PROBLEM*** close(fd); return 0;} </code></pre> <hr> <p>The output</p> <pre><code>80 20 21 0 Partation ID:83 Starting Sector:0800 </code></pre> <p>This in hexa 800h i need it in decimal 2048</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. 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