当前位置:网站首页>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;
}
边栏推荐
- 556. 下一个更大元素 III
- Exercise 6-6 use a function to output an integer in reverse order
- Leetcode(4)——寻找两个正序数组的中位数
- page owner特性浅析
- Exercise 10-6 recursively find Fabonacci sequence
- x86汇编语言-从实模式到保护模式 笔记
- JS get DPI, PX to cm, cm to PX
- Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
- 中国锂电池电解液行业市场专项调研报告(2022版)
- JS shift operators (< <,> > and > > >)
猜你喜欢

Message subscription and publishing

Understanding of closures

7-8 overspeed judgment

Exercise 8-7 string sorting

concat和concat_ws()区别及group_concat()和repeat()函数的使用

QT learning 24 layout manager (III)

全局事件总线
[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)"/>MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)

28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;

Redis:字符串類型數據的操作命令
随机推荐
Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride(
protobuf与grpc
Leetcode (4) -- find the median of two positively ordered arrays
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?
中国PETG市场预测及战略研究报告(2022版)
关于回溯问题中的排列问题的思考(LeetCode46题与47题)
Solve the problem of dormitory router campus network sharing login
Exercise 10-3 recursive implementation of exponential functions
八大排序
7-8 overspeed judgment
Uniapp skills - scrolling components -1
7-7 12-24 hour system
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
[clean up the extraordinary image of Disk C]
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
Page generation QR code