PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 11, 2022

[FIXED] How to merge two Hex numbers to one number and then convert it into decimal.?

 August 11, 2022     c, decimal, hex, merge, numbers     No comments   

Issue

I am making a C program in which I have two hex numbers, i.e. num1=25 num2=71 which are in hex. I want to make it as num3=2571 and then I have to convert 2571 into a decimal number. How do I do this? Please help, Thanks!


Solution

Just shift the digits and combine

int num1,num2,num3;
num1=0x25;
num2=0x71;
num3=(num1<<8)|(num2);
printf("%x %d",num3,num3);

You need to place 25 (0025) followed by 71 (0071) in a variable, so you have to left shift the first number by 8 bits (0025 to 2500) and combine it with num2. Logical Or is the equivalent for combining, hence the | symbol.



Answered By - Nerdy
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing