当前位置:网站首页>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;
}
边栏推荐
- Solution to failure or slow downloading of electron when electron uses electron builder to package
- JS download files through URL links
- 可编程逻辑器件软件测试
- protobuf与grpc
- Vite project commissioning
- Solve the problem of dormitory router campus network sharing login
- Although not necessarily the best, it must be the hardest!
- 常见问题之PHP——ldap_add(): Add: Undefined attribute type in
- Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
- Similarities and differences of sessionstorage, localstorage and cookies
猜你喜欢
[email protected] Nanoparticles) | nano metal organic framework carry"/>
Metal organic framework material zif-8 containing curcumin( [email protected] Nanoparticles) | nano metal organic framework carry
剑指 Offer 28. 对称的二叉树
Exercise 6-1 classify and count the number of characters
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
Leetcode (4) -- find the median of two positively ordered arrays
Interface for querying IP home
QT learning 20 standard dialog box in QT (middle)
Why are grass-roots colleges and universities with "soil and poverty" called "Northeast small Tsinghua"?
[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)"/>
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
Exercise 9-3 plane vector addition
随机推荐
Vite project commissioning
Redis: commandes d'action pour les données de type chaîne
FPGA测试方法以Mentor工具为例
QT learning 23 layout manager (II)
Exercise 6-1 classify and count the number of characters
Canvas utility library fabric JS user manual
[acnoi2022] guess numbers
Interface for querying IP home
超简单手机地图开发
Uniapp tips - set background music
Exercise 10-8 recursive implementation of sequential output of integers
关于回溯问题中的排列问题的思考(LeetCode46题与47题)
Exercise 8-8 moving letters
金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
Leetcode(4)——寻找两个正序数组的中位数
Raft 协议
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
C library function - qsort()
Page generation QR code
JVM garbage collector