| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 360 人关注过本帖
标题:字符型数据的运算一点问题
只看楼主 加入收藏
tk1223108078
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2013-7-18
结帖率:77.78%
收藏
 问题点数:0 回复次数:1 
字符型数据的运算一点问题
int main()
{
    HANDLE hFile = CreateFile("\\\\.\\PhysicalDrive1",//\\\\.\\PhysicalDrive0..D://123.txt
                       GENERIC_READ|GENERIC_WRITE,
                       FILE_SHARE_READ,
                       NULL,
                       OPEN_EXISTING,
                       0,//FILE_FLAG_OVERLAPPED,
                       NULL);

    DWORD RSize=0;
    OVERLAPPED overlap;
    unsigned char MBRbuf[512]={0};
    memset(&overlap,0,sizeof(overlap));
    overlap.OffsetHigh = (DWORD)(0*512ull / 0x100000000ull );
    overlap.Offset     = (DWORD)(0*512ull % 0x100000000ull );//实现偏移
    ReadFile(hFile, MBRbuf, 512, &RSize, &overlap);
    int startSector=454;//判断分区表存在与否的参数
    int DBRsector[20]={0};
    int startDBRsector;
    while(MBRbuf[startSector]!=0||MBRbuf[startSector+1]!=0||MBRbuf[startSector+2]!=0||MBRbuf[startSector+3]!=0)//判断分区表项里记录起始位置的地方是否有数据,也是退出循环的判断
    {
        for(int i=0;i<=7;i=i+2)//按位数存放分区起始位置
        {
            DBRsector[i]=getTall(MBRbuf[startSector+3]);
            DBRsector[i+1]=getLow(MBRbuf[startSector+3]);
            startSector=startSector-1;
        }
        for(int i=0;i<=7;i++)
        {
            printf("%0X",DBRsector[i]);
            //startDBRsector+=(DBRsector[i])*pow(16,i);
        }
        printf("\n");
        printf("%d\n",startDBRsector);
        memset(DBRsector,0,20);//清零保证空
        startSector+=20;//前面减过4
    }
这里startDBRsector+=(DBRsector[i])*pow(16,i)出现了问题,
DBRsector[i]是字符类型的数据,现在我想把这数组连接起来的数据转换为10进制的整形数值,如何实现。
2014-03-11 20:34
tk1223108078
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2013-7-18
收藏
得分:0 
还有写代码在这里
#include<stdio.h>
#include<process.h>
#include <math.h>
#include<stdint.h>
#include<windows.h>
int getTall(unsigned char buf)
{
    return buf/16;
}

int getLow(unsigned char buf)
{
    return buf%16;
}
2014-03-11 20:36
快速回复:字符型数据的运算一点问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019880 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved