当前位置:网站首页>7-4 BCD decryption (10 points)
7-4 BCD decryption (10 points)
2022-07-03 14:14:00 【Big fish】
BCD A number is a two digit decimal number expressed in one byte , Every four bits represent one bit . So if a BCD The hexadecimal number is 0x12, It expresses decimal 12. But Xiao Ming didn't learn BCD, Put all the BCD Numbers are converted into decimal output as binary numbers . therefore BCD Of 0x12 It is output as decimal 18 了 !
Now? , Your program needs to read this wrong decimal number , Then output the correct decimal number . Tips : You can take 18 Convert back to 0x12, And then switch back to 12.
( Make complaints about it , In fact, this topic is 10 Decimal conversion BCD Format alphabetic 16 Base number , Don't be confused by questions )
Extended reading Decimal to hexadecimal C Language explanation _ Learning notes , For reference only -CSDN Blog _c Language decimal to hexadecimal
Here, first explain what is BCD Count :
Decimal 15 BIN Expressed as 1111(BIN In fact, it refers to binary data , Meet 2 Just write forward 1, Change the original position to zero , The number that has been written according to this rule )
BCD In fact, it means Write a number in groups of binary numbers , such as :
Decimal 15 BCD Expressed as 0001 0101
Input format :
Input gives a... In one line [0, 153] Positive integer in range , Ensure that it can be converted back to a valid BCD Count , In other words, this integer will not appear when converted to hexadecimal A-F The number of .
Output format :
Output the corresponding decimal number .
sample input :
18
sample output :
12
Reference code
#include <stdio.h>
int main()
{
int n, cnt = 0, t = 1, num = 0;
int s[2];
scanf("%d", &n);
// Decimal to hexadecimal
while (n)
{
s[cnt] = n % 16;
t *= 16;
n /= 16;
cnt++;
}
if (s[1] != 0)
printf("%d", s[1]);
printf("%d\n", s[0]);
return 0;
}
Another way to do it
#include <stdio.h>
int main()
{
int i,j,k;
scanf("%d", &i);
j = i / 16;
k = i % 16;
printf("%d\n", j*10+k);
return 0;
}
边栏推荐
- [combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
- fpga阻塞赋值和非阻塞赋值
- js 2023. String pair equal to the target string after connection
- Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?
- 愉悦资本新双币基金近40亿元完成首次关账
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- 【吉林大学】考研初试复试资料分享
- Simulated access
- Redis:字符串類型數據的操作命令
- Similarities and differences of sessionstorage, localstorage and cookies
猜你喜欢
Solution to failure or slow downloading of electron when electron uses electron builder to package
QT learning 24 layout manager (III)
Redis: commandes d'action pour les données de type chaîne
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
QT learning 17 dialog box and its types
QT learning 20 standard dialog box in QT (middle)
7-11 calculation of residential water charges by sections
Redis:字符串類型數據的操作命令
Redis:字符串类型数据的操作命令
Leetcode(4)——寻找两个正序数组的中位数
随机推荐
[clean up the extraordinary image of Disk C]
JS Part III
Redis:字符串类型数据的操作命令
Solution to failure or slow downloading of electron when electron uses electron builder to package
Exercise 8-8 moving letters
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
Current situation, analysis and prediction of information and innovation industry
Exercise 10-1 calculate the sum of 1 to n using recursive functions
玖逸云黑免费无加密版本源码
Eight sorts
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
战略、战术(和 OKR)
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
JS general form submission 1-onsubmit
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
simpleParallax. JS (create poor visual effects for website pictures)
Exercise 6-6 use a function to output an integer in reverse order
JS get DPI, PX to cm, cm to PX
Analysis of the characteristics of page owner
Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content