LBA与C/H/S相互转化计算--计算扇区数量,含c++计算
生活随笔
收集整理的這篇文章主要介紹了
LBA与C/H/S相互转化计算--计算扇区数量,含c++计算
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
計算扇區(qū)時需要轉(zhuǎn)換 LBA與C/H/S
C/H/S | Cylinder/Head/Sector | 柱面/磁頭/扇區(qū) ,是舊式磁盤尋道方式
LBA | Logical Block Address ,是抽象的扇區(qū),可以理解為線性直鋪的扇區(qū),從0–max
以下是c++計算
#include <iostream>using namespace std;void printChoice() {cout << "[1] LBA to C/H/S" << endl;cout << "[2] C/H/S to LBA" << endl;cout << "input choice: ";return; } //CS表示起始柱面號,HS表示起始磁頭號,SS表示起始扇區(qū)號,PS表示每磁道扇區(qū)數(shù),PH表示每柱面磁道數(shù),CS=0,HS=0,SS=1,PS=63,PH=255/* C=LBA / (PH x PS)+CS , /是整除,求商,%模,求余數(shù) H=(LBA / PS)% PH+HS S=LBA % PS+SS */ void lBAtoCHS(unsigned int lba) {cout << "get LBA:"<<lba<<endl;unsigned int c, h, s;c = lba / (255 * 63);h = (lba / 63) % 255;s = lba % 63 + 1;cout << "to C/H/S: " << c << "/" << h << "/" << s << endl;return; }/* LBA=(C–CS)﹡PH﹡PS+(H–HS)﹡PS+(S–SS)-1 */ void cHStoLBA(unsigned int c, unsigned int h, unsigned int s) {cout << "get C/H/S:"<<c<<"/"<<h<<"/"<<s <<endl;unsigned int lba;lba = c * 255 * 63 + h * 63 + s - 1;cout << "toLBA: " << lba << endl;return; }int main() { start:printChoice();unsigned int choice,lba,c,h,s;cin >> choice;switch (choice){case 1:cout << "input LBA: ";cin >> lba;lBAtoCHS(lba);break;case 2:cout << "input C/H/S each with delimiter(space): ";cin >> c >> h >> s;cHStoLBA(c,h,s);break;default:goto start;break;}return 0; }總結(jié)
以上是生活随笔為你收集整理的LBA与C/H/S相互转化计算--计算扇区数量,含c++计算的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android实例——拼图游戏
- 下一篇: 基于GEE平台的植被覆盖度(FVC)像元