Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:28:14+00:00 2026-05-26T02:28:14+00:00

I’m trying to make fdisk program in Linux. I have a buffer which contains

  • 0

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).

The problem that I have buffer array char buf[512] and that buffer contains the needed info and I want to print it in decimal. The result should be dec 2048 but my program print hex 0800

The program can see each digit eight zero zero and I want it to see eight hundreds.


The Code

#define _LARGEFILE64_SOURCE
#define buff_SIZE 512

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>


int main(int argc, char ** argv){


  int fd; // File descriptor
  unsigned char buf[buff_SIZE];

  if(argc<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<=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;}

The output

80
20
21
0
Partation ID:83
Starting Sector:0800

This in hexa 800h i need it in decimal 2048

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:28:15+00:00Added an answer on May 26, 2026 at 2:28 am
    printf("Starting Sector:%lu\n",
             (unsigned long)buf[454] * 0x1000
           + (unsigned long)buf[455] * 0x100
           + (unsigned long)buf[456] * 0x10
           + (unsigned long)buf[457] * 0x1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.