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 7776241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:49:54+00:00 2026-06-01T17:49:54+00:00

I have a string SOMETHING /\xff and I want to save the hex representation

  • 0

I have a string "SOMETHING /\xff" and I want to save the hex representation of 0xff into a char buffer. So I strncpy everything after the forward slash (/) into my buffer (let’s call it buff).

However, when I use the gdb command print \x buff to view the contents of buff, it doesn’t show 0xff. Any ideas as to what could be wrong? Is it possible that my forward slash is messing things up?

  • 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-06-01T17:49:55+00:00Added an answer on June 1, 2026 at 5:49 pm

    I think your problem has to do with the way you’re printing the variable in gdb. Take this simple program, compile as debug (-g if using gcc), and run and break at the first puts statement:

    int main(void)
    {
       char *ptr = "str \xff";
       char arr[] = "str \xff";
       puts(ptr);
       puts(arr);
    
       return 0;
    }
    

    If I try and print ptr the way you’ve mentioned, p /x ptr, it’ll print the value of ptr (the address it’s pointing to):

    (gdb) p /x ptr
    $1 = 0x4005f8
    

    However if I do the same command for arr, I’ll get:

    (gdb) p /x arr
    $2 = {0x73, 0x74, 0x72, 0x20, 0xff, 0x0}
    

    That’s because gdb can see that arr is of type char[6] and not char*. You can get the same results with the command p /x "str \xff", which is useful for testing things:

    (gdb) p /x "str \xff"
    $3 = {0x73, 0x74, 0x72, 0x20, 0xff, 0x0}
    

    Now if you want to be able to print a certain amount of bytes from the address pointed to by a pointer, use the examine (x) memory command instead of print (p):

    (gdb) x/6bx ptr
    0x4005f8 <__dso_handle+8>:  0x73    0x74    0x72    0x20    0xff    0x00
    

    That’ll print 6 bytes in hex from the address pointed to by ptr. Try that with your buff variable and see how you go.

    Alternatively, another thing you can try is:

    (gdb) p /x (char[6])*ptr
    $4 = {0x73, 0x74, 0x72, 0x20, 0xff, 0x0}
    

    This will treat the char pointed to by ptr as the first element in an array of 6 chars, and will allow you to use the print command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I simply have a string that looks something like this: 7,true,NA,false:67,false,NA,false:5,false,NA,false:5,false,NA,false All I want
I have this String : String myStr = something.bad@foo.us I want to get just
I have a string that is something like Firstname LastnameFirstname Lastname and I want
I have string: text and something and something like f213 @@ -1,9 +1,11 @@
I have a string containing something like this Hello bla bla bla bla ok,
I have a string which comes from the DB. the string is something like
I have a string that looks something like: 'a 'b '(d f g (1
I have two classes class A { public string something { get; set; }
I have a string 2010-08-02 12:13:06.0 and need to get something like Fri Aug
I have this line in the declarations section: Private filePath As String And something

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.