Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 553807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:38:37+00:00 2026-05-13T11:38:37+00:00

Using scanf, each number typed in, i would like my program to print out

  • 0

Using scanf, each number typed in, i would like my program to
print out two lines: for example

byte order: little-endian

> 2
     2 0x00000002
  2.00 0x40000000

> -2
    -2 0xFFFFFFFE
 -2.00 0xC0000000

I can get it to print out the 2 in hex
but i also need a float and of course i cant scanf as one
when i need to also scan as an int

If i cast as a float when i try to printf i get a zero. If i scan in as a float
i get the correct output. I have tried to convert the int to a
float but it still comes out as zero.

here is my output so far

Int - float - hex

byte order: little-endian

>2

         2  0x000002
      2.00  00000000

it looks like i am converting to a float fine
why wont it print as a hex?
if i scan in as a float i get the correct hex representation like the first example.
this should be something simple. i do need to scan in as a decimal
keep in mind
i am running this in cygwin

here is what i have so far..

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{


int HexNumber;
    float convert;
printf("Int - float - hex\n");



int a = 0x12345678;
unsigned char *c = (unsigned char*)(&a);
if (*c == 0x78)
{
    printf("\nbyte order: little-endian\n");
}
else
{
    printf("\nbyte order: big-endian\n");
}

printf("\n>");
scanf("%d", &HexNumber);
printf("\n%10d  ",HexNumber);
printf("%#08x",HexNumber);





convert =  (float)HexNumber; // converts but prints a zero

printf("\n%10.2f  ", convert); 
printf("%#08x", convert); // prints zeros


return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:38:38+00:00Added an answer on May 13, 2026 at 11:38 am

    try this:

    int i = 2;
    float f = (float)i;
    printf("%#08X", *( (int*) &f ));
    

    [EDIT]

    @Corey:

    let’s parse it from inside out:

    &  f = address of f = say address 0x5ca1ab1e
    (int*)  &f = interpret the address 0x5ca1ab1e as integer pointer
    *  ((int*)&f) = get the integer at address 0x5ca1ab1e
    

    the following is more concise, but it’s hard to remember the C language’s operator associativity and operator precedence(i prefer the extra clarity of some added parenthesis and whitespace provides):

    printf("%#08X", *(int*)&f);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the example code, I'm using these functions for a program, but scanf
I am using fscanf to read a file which has lines like Number <-whitespace->
I have a binary of a program that waits for an input using scanf.
I would like to scan a large piece of text using PHP and find
I'm trying to compare a string stored in a structure. I'm using scanf to
I'm writing a program that list the digits of integer input. example: Please enter
How would one go about retrieving scan lines for all the lines in a
I have written a program using Free Pascal and the Lazarus IDE. In brief,
I'm writing a program that scans a text file for the byte offset of
Here is my situation. I am using two java.util.HashMap to store some frequently used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.