当前位置:网站首页>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;
}
边栏推荐
- Exercise 6-6 use a function to output an integer in reverse order
- FPGA测试方法以Mentor工具为例
- QT learning 22 layout manager (I)
- Redis:Redis的数据结构、key的操作命令
- JVM object lifecycle
- 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
- Solve the problem of dormitory router campus network sharing login
- How to bold text in AI
- Leetcode(4)——尋找兩個正序數組的中比特數
- 6-9 statistics of single digits (15 points)
猜你喜欢

Exercise 6-6 use a function to output an integer in reverse order

Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)

Message subscription and publishing

jvm-对象生命周期

小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。

Print. JS -- web page file printing

Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)

556. 下一个更大元素 III

jvm-运行时数据区

Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
随机推荐
Common plug-ins for vite project development
Programmable logic device software testing
Simulated access
Leetcode(4)——寻找两个正序数组的中位数
[ACNOI2022]猜数
Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
jvm-类加载
selenium 浏览器(1)
JVM garbage collector
2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
page owner特性浅析
Exercise 10-1 calculate the sum of 1 to n using recursive functions
etcd集群权限管理和账号密码使用
js 2023. String pair equal to the target string after connection
JS continues to explore...
Redis:字符串类型数据的操作命令
Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线