Computing desk | ||
---|---|---|
< December 30 | << Nov | December | Jan >> | Current desk > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
I'm an absolute beginner. I just joined codeacademy last month and more recently I've enrolled in Edx's premiere computer science class CS50! I just learned through wikipedia how to find the memory addresses of any data type just by typing "%p, &shark inside the printf function and now I'm like a giraffe who discovered the stepladder!
Is there a clean, fool-proof way for me view the 8, 16, 32, or 64 bits of ANY memory location just by having that memory location's address? (e.g. 0x7ffed73897d8) In other words—if I know the address—is there a program or line of code which can "print for me the 8, 16, 32, or 64 bits of binary information" at the known address? 67.233.34.199 ( talk) 03:03, 31 December 2017 (UTC)
stdint.h
. Note this requires C99, but if you're trying to learn in an environment without C99 support, throw it out and use one that does. Note you will see a lot of stuff online telling you to do things like use a char*
to read a single byte. This is wrong in plain C because the size of types like char
is platform-dependent. Using char
as a synonym for "8-bit byte" was common in pre-standard C, and old habits die hard. With that said,
POSIX does mandate char
be exactly eight bits, so if you're writing explicitly for POSIX platforms you can assume that. Here's an example for looking at a 32-bit chunk of memory. As I said, on modern platforms you can't access arbitrary memory addresses, so instead we're just going with whatever the operating system gives us off the
heap with
malloc.#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int main() {
uint32_t *ptr = malloc(sizeof(uint32_t));
if(!ptr){return 1;}
printf("Value: 0x%x Address:0x%x\n", *ptr, ptr);
free(ptr);
}
malloc
failure, and free
ing the malloc
ed memory after using it. Obviously this isn't necessary in a toy program, but in "real" programming you should always do these. Note as well that forgetting to assign something to a malloc
ed pointer is a common mistake. Here it isn't a mistake because we want to see whatever's in the memory location already. It's possible that you might always get a value of 0, because these days it's increasingly common for systems to zero out memory when it's allocated by a process. --
47.157.122.192 (
talk)
10:48, 31 December 2017 (UTC)
#include <stdio.h>
#include <inttypes.h>
#include <stdint.h>
void print_values(uint64_t* p){
printf ("values at %p:\n", p);
printf (" 8 bit: %02" PRIx8 "\n", (uint8_t)*p);
printf (" 16 bit: %04" PRIx16 "\n", (uint16_t)*p);
printf (" 32 bit: %08" PRIx32 "\n", (uint32_t)*p);
printf (" 64 bit: %016" PRIx64 "\n", (uint64_t)*p);
}
int main () {
const char test_data[] = { 0x12, 0x34, 0x56, 0x78,
0xf1, 0xe2, 0xd3, 0xe4 };
print_values((uint64_t*)test_data);
return 0;
}
printf("%d\n",*(int*)0x7ffed73897d8);
I'm happier than a clam at high tide! Now I have a whole host of experiments I'm wishing to do because I want to test and verify for myself a lot of questions along the lines of "what will happen if I do x" and I needed to know this particular line of code. The other solutions worked when I ran them in codeblocks (although not in the cloud ide that CS50 uses) but I didn't fully understand what I was seeing nor how to tinker & substitute my own memory addresses into the code, which is fine for now.
The other great thing I really like about computer programming is the absolute freedom you have to write and instruct the computer to do anything you want — no questioning, no second-guessing, no backtalk — especially if you are the type of person who gets joy at telling the computer to perform purposeless tasks. Thanks again, everyone! 67.233.34.199 ( talk) 11:57, 1 January 2018 (UTC)
I don’t know if this is an appropriate place to post this or if I should frame the question differently. I’m going to go ahead and explain and ask. I recently went on a trip where I took a lot of videos. I have a USB drive that you can put in to an iPhone on one end and the computer on the other end. To free up some space on my iPhone to continue recording, I moved some of the video clips directly to the USB drive. However, when I returned home and started going over the videos I put in my USB drive, my computer and my iPhone were unable play the videos except for the first few. 9 of the videos won’t even copy and paste to my computer. Is such an issue fixable? Who are what would be able to fix corrupted/unplayable videos? Willminator ( talk) 03:22, 31 December 2017 (UTC)
I'm not convinced it's anywhere near as difficult as you suggest. You use something like Chipgenius [1] to work out what the controller and flash chip is, then you look and see if there's a leaked controller manufacturer tool which supports your flash chip. The later can be complicated, I don't know about other manufacturers but for SMI controllers at least, the latest tool doesn't necessarily support all controllers and flash chips supported by older versions, perhaps not that surprising since these aren't intended for end users. Still provided what you have isn't too obscure you might have hope.
There are a lot of guides and stuff online although a lot of the best stuff is in Russian. (I think there's also a fair amount of stuff in Chinese but it doesn't show up as much or get linked from the English guises etc.) [2] [3] [4] [5] [6]. Although this forum at least does seem to accept stuff in English [7].
Note that these guides aren't really intended for re-flashing a USB key with dodgy firmware that reports a false capacity, but instead to try and fix drives which start showing up as 'smi usb memory bar' or something like that. Still the way you do this is normally by flashing a stock firmware which should most likely solve such false capacity problems. I believe that this often also kills the bad blocks list of the stick, I can't remember offhand or perhaps I never found out how to fix this although it may simply entail writing and reading the whole disk a few times, or maybe the flash software does that.
Note as at least one of the guides warns, you should consider carefully what you are doing if you're trying to fix a drive with false capacity since who knows where they got the memory chip from and what its quality and condition are. (While this may apply to a drive that breaks, it does appear often these are mostly just cases where the firmware somehow got messed up and the flash chip itself isn't significantly damaged.)
Nil Einne ( talk) 12:38, 5 January 2018 (UTC)
Apple's iPhone don't have memory card slot. It's RAM is not more than 1gb (5 or 4 model). It's screen size is smaller than Android phones. Inspite of all these factors people buy it at awesome prices! (Which are far far higher than Androids having all I have just mentioned).Why is that? No, it can't be just brand mania. Or is it? Jon Ascton (talk) 07:02, 31 December 2017 (UTC)
Computing desk | ||
---|---|---|
< December 30 | << Nov | December | Jan >> | Current desk > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
I'm an absolute beginner. I just joined codeacademy last month and more recently I've enrolled in Edx's premiere computer science class CS50! I just learned through wikipedia how to find the memory addresses of any data type just by typing "%p, &shark inside the printf function and now I'm like a giraffe who discovered the stepladder!
Is there a clean, fool-proof way for me view the 8, 16, 32, or 64 bits of ANY memory location just by having that memory location's address? (e.g. 0x7ffed73897d8) In other words—if I know the address—is there a program or line of code which can "print for me the 8, 16, 32, or 64 bits of binary information" at the known address? 67.233.34.199 ( talk) 03:03, 31 December 2017 (UTC)
stdint.h
. Note this requires C99, but if you're trying to learn in an environment without C99 support, throw it out and use one that does. Note you will see a lot of stuff online telling you to do things like use a char*
to read a single byte. This is wrong in plain C because the size of types like char
is platform-dependent. Using char
as a synonym for "8-bit byte" was common in pre-standard C, and old habits die hard. With that said,
POSIX does mandate char
be exactly eight bits, so if you're writing explicitly for POSIX platforms you can assume that. Here's an example for looking at a 32-bit chunk of memory. As I said, on modern platforms you can't access arbitrary memory addresses, so instead we're just going with whatever the operating system gives us off the
heap with
malloc.#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int main() {
uint32_t *ptr = malloc(sizeof(uint32_t));
if(!ptr){return 1;}
printf("Value: 0x%x Address:0x%x\n", *ptr, ptr);
free(ptr);
}
malloc
failure, and free
ing the malloc
ed memory after using it. Obviously this isn't necessary in a toy program, but in "real" programming you should always do these. Note as well that forgetting to assign something to a malloc
ed pointer is a common mistake. Here it isn't a mistake because we want to see whatever's in the memory location already. It's possible that you might always get a value of 0, because these days it's increasingly common for systems to zero out memory when it's allocated by a process. --
47.157.122.192 (
talk)
10:48, 31 December 2017 (UTC)
#include <stdio.h>
#include <inttypes.h>
#include <stdint.h>
void print_values(uint64_t* p){
printf ("values at %p:\n", p);
printf (" 8 bit: %02" PRIx8 "\n", (uint8_t)*p);
printf (" 16 bit: %04" PRIx16 "\n", (uint16_t)*p);
printf (" 32 bit: %08" PRIx32 "\n", (uint32_t)*p);
printf (" 64 bit: %016" PRIx64 "\n", (uint64_t)*p);
}
int main () {
const char test_data[] = { 0x12, 0x34, 0x56, 0x78,
0xf1, 0xe2, 0xd3, 0xe4 };
print_values((uint64_t*)test_data);
return 0;
}
printf("%d\n",*(int*)0x7ffed73897d8);
I'm happier than a clam at high tide! Now I have a whole host of experiments I'm wishing to do because I want to test and verify for myself a lot of questions along the lines of "what will happen if I do x" and I needed to know this particular line of code. The other solutions worked when I ran them in codeblocks (although not in the cloud ide that CS50 uses) but I didn't fully understand what I was seeing nor how to tinker & substitute my own memory addresses into the code, which is fine for now.
The other great thing I really like about computer programming is the absolute freedom you have to write and instruct the computer to do anything you want — no questioning, no second-guessing, no backtalk — especially if you are the type of person who gets joy at telling the computer to perform purposeless tasks. Thanks again, everyone! 67.233.34.199 ( talk) 11:57, 1 January 2018 (UTC)
I don’t know if this is an appropriate place to post this or if I should frame the question differently. I’m going to go ahead and explain and ask. I recently went on a trip where I took a lot of videos. I have a USB drive that you can put in to an iPhone on one end and the computer on the other end. To free up some space on my iPhone to continue recording, I moved some of the video clips directly to the USB drive. However, when I returned home and started going over the videos I put in my USB drive, my computer and my iPhone were unable play the videos except for the first few. 9 of the videos won’t even copy and paste to my computer. Is such an issue fixable? Who are what would be able to fix corrupted/unplayable videos? Willminator ( talk) 03:22, 31 December 2017 (UTC)
I'm not convinced it's anywhere near as difficult as you suggest. You use something like Chipgenius [1] to work out what the controller and flash chip is, then you look and see if there's a leaked controller manufacturer tool which supports your flash chip. The later can be complicated, I don't know about other manufacturers but for SMI controllers at least, the latest tool doesn't necessarily support all controllers and flash chips supported by older versions, perhaps not that surprising since these aren't intended for end users. Still provided what you have isn't too obscure you might have hope.
There are a lot of guides and stuff online although a lot of the best stuff is in Russian. (I think there's also a fair amount of stuff in Chinese but it doesn't show up as much or get linked from the English guises etc.) [2] [3] [4] [5] [6]. Although this forum at least does seem to accept stuff in English [7].
Note that these guides aren't really intended for re-flashing a USB key with dodgy firmware that reports a false capacity, but instead to try and fix drives which start showing up as 'smi usb memory bar' or something like that. Still the way you do this is normally by flashing a stock firmware which should most likely solve such false capacity problems. I believe that this often also kills the bad blocks list of the stick, I can't remember offhand or perhaps I never found out how to fix this although it may simply entail writing and reading the whole disk a few times, or maybe the flash software does that.
Note as at least one of the guides warns, you should consider carefully what you are doing if you're trying to fix a drive with false capacity since who knows where they got the memory chip from and what its quality and condition are. (While this may apply to a drive that breaks, it does appear often these are mostly just cases where the firmware somehow got messed up and the flash chip itself isn't significantly damaged.)
Nil Einne ( talk) 12:38, 5 January 2018 (UTC)
Apple's iPhone don't have memory card slot. It's RAM is not more than 1gb (5 or 4 model). It's screen size is smaller than Android phones. Inspite of all these factors people buy it at awesome prices! (Which are far far higher than Androids having all I have just mentioned).Why is that? No, it can't be just brand mania. Or is it? Jon Ascton (talk) 07:02, 31 December 2017 (UTC)