Skip to content

Instantly share code, notes, and snippets.

@StefanoFiumara
Created November 16, 2013 02:58
Show Gist options
  • Save StefanoFiumara/7495375 to your computer and use it in GitHub Desktop.
Save StefanoFiumara/7495375 to your computer and use it in GitHub Desktop.
int VirtualMemoryManager::convert_from_hex(string h) {
h = h.substr(2); //truncate the 0x portion
int result = 0;
//magic, converts to int, stores in result
sscanf(h.c_str(), "%x", &result);
return result;
}
int VirtualMemoryManager::get_segment(int ins) {
return (ins >> 6) & 3;
}
int VirtualMemoryManager::get_page(int ins) {
return (ins >> 4) & 3;
}
int VirtualMemoryManager::get_offset(int ins) {
return ins & 15;
}
@zmughal
Copy link

zmughal commented Nov 18, 2013

Try this:

#include <stdio.h>

int main() {
    int result;
    sscanf("0xFF", "%x", &result); /* can handle the 0x in front */
    printf("%d\n", result);
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment