Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to work with base 16 in C

1 Answer

0 votes
#include <stdio.h>
 
int main(void)
{
    unsigned int n;
     
    printf("Enter hex number: ");
    scanf("%x", &n); // %x - input hex numbers
    printf("n (base 10) = %d\n", n);
     
    printf("Enter a number: ");
    scanf("%d", &n);
    printf("n (base 16) = %x\n", n); // %x - output hex number
     
    n = 6670; // set deciaml number
    printf("n (base 16) = %x\n", n);
    n = 0x1A0E; // set hex number, note the: 0x before the number
    printf("n (base 16) = %x\n", n);
  
    return 0;
}


/*
run:

Enter hex number: 16
n (base 10) = 22
Enter a number: 255
n (base 16) = ff
n (base 16) = 1a0e
n (base 16) = 1a0e

*/


answered May 17, 2014 by avibootz
edited Feb 27, 2025 by avibootz
...