如何使用printf()以十六进制形式逐个读取内存字节(因此没有任何格式)(how to read memory bytes one by one in hex(so without any format) with printf())
我有兴趣在使用ubentu上的netbeans读取C.Im中的一个字节的内存,下面是我的代码只读取一个字节(不是a的整个值)。 但屏幕上没有打印出任何内容。
main() { int a[1]={3}; //printf(%d",a[0]); //line 2 printf("\x07",a[0]); //line 3 }
在我的想法中,带有标签a的地址中的内存由以下内容组成:
- 0x0004 03
- 0x0008 00
- 0x000c 00
- 0x000f 00
第2行中的printf()语句表示转到地址0x ??? 4和:
- 读取4个字节(因为d字符)
- 将这4个字节表示为数字意味着将它们乘以2的幂(因为d字符)
第3行中的printf()语句使用\ (而不是%)和0到7(1字节)的位。 所以它表明,去地址0x0004和:
- 项目清单
- 读取1个字节(因为07个字符)2 - 除了将每个4位显示为十六进制值外什么都不做
所以代码应该打印出0x0004中的第一个字节是03.但事实并非如此。 任何线索?
提前致谢
请不要只是纠正我的语法。 你认为我的假设在printf格式化方面是否正确?
I'm interested to read one byte of memory in C.Im using netbeans on ubuntu and below is my code to read just one byte(not the whole value of a). but nothing is printed out on the screen.
main() { int a[1]={3}; //printf(%d",a[0]); //line 2 printf("\x07",a[0]); //line 3 }
in my idea, the memory in address with label a is composed of:
- 0x0004 03
- 0x0008 00
- 0x000c 00
- 0x000f 00
printf() statement in line 2 indicates that go to the address 0x???4 and :
- read 4 bytes (because of d character)
- Represent these 4 bytes as a number meaning that multiply them by power of 2 (because of d character)
printf() statement in line 3 use \ (and not %) and bits from 0 to 7 (1 byte). so it indicates that, go address 0x0004 and:
- List item
- read 1 byte (because of 07 characters) 2-Do nothing except that show each 4-bit as a hex value
so the code should print out what the first byte in 0x0004 which is 03. but it does not. any clue?
Thanks in advance
Please don't just correct my syntax. Do you think my hypotheses are correct regarding formatters in printf?
原文:
最满意答案
是的,我做到了。 我认为Javascript无法找到“miserable.json”,也无法访问其中的节点。 我这样说是因为我已经将“miserables.json”的内容分配给定义为“index.html”的对象而没有成功。 然后,我创建了一个节点数组(没有将它们标识为节点),将数组的代码粘贴到“index.html”文件中,并编写了一个for循环打印尽可能多的“hello wolrd”,因为阵列; 起初,浏览器说d3没有定义,然后当我引用在线d3库的url而不是我的计算机上的d3文件夹时,它工作了。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>D3 Test</title> <script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> </head> <body> <script type="text/javascript"> var dataset = [{"name":"Myriel","group":1}, {"name":"Napoleon","group":1}, {"name":"Mlle.Baptistine","group":1}, {"name":"Mme.Magloire","group":1}, {"name":"CountessdeLo","group":1}, {"name":"Geborand","group":1}, {"name":"Champtercier","group":1}, {"name":"Cravatte","group":1}, {"name":"Count","group":1}, {"name":"OldMan","group":1}, {"name":"Labarre","group":2}, {"name":"Valjean","group":2}, {"name":"Marguerite","group":3}, {"name":"Mme.deR","group":2}, {"name":"Isabeau","group":2}, {"name":"Gervais","group":2}, {"name":"Tholomyes","group":3}, {"name":"Listolier","group":3}, {"name":"Fameuil","group":3}, {"name":"Blacheville","group":3}, {"name":"Favourite","group":3}, {"name":"Dahlia","group":3}, {"name":"Zephine","group":3}, {"name":"Fantine","group":3}, {"name":"Mme.Thenardier","group":4}, {"name":"Thenardier","group":4}, {"name":"Cosette","group":5}, {"name":"Javert","group":4}, {"name":"Fauchelevent","group":0}, {"name":"Bamatabois","group":2}, {"name":"Perpetue","group":3}, {"name":"Simplice","group":2}, {"name":"Scaufflaire","group":2}, {"name":"Woman1","group":2}, {"name":"Judge","group":2}, {"name":"Champmathieu","group":2}, {"name":"Brevet","group":2}, {"name":"Chenildieu","group":2}, {"name":"Cochepaille","group":2}, {"name":"Pontmercy","group":4}, {"name":"Boulatruelle","group":6}, {"name":"Eponine","group":4}, {"name":"Anzelma","group":4}, {"name":"Woman2","group":5}, {"name":"MotherInnocent","group":0}, {"name":"Gribier","group":0}, {"name":"Jondrette","group":7}, {"name":"Mme.Burgon","group":7}, {"name":"Gavroche","group":8}, {"name":"Gillenormand","group":5}, {"name":"Magnon","group":5}, {"name":"Mlle.Gillenormand","group":5}, {"name":"Mme.Pontmercy","group":5}, {"name":"Mlle.Vaubois","group":5}, {"name":"Lt.Gillenormand","group":5}, {"name":"Marius","group":8}, {"name":"BaronessT","group":5}, {"name":"Mabeuf","group":8}, {"name":"Enjolras","group":8}, {"name":"Combeferre","group":8}, {"name":"Prouvaire","group":8}, {"name":"Feuilly","group":8}, {"name":"Courfeyrac","group":8}, {"name":"Bahorel","group":8}, {"name":"Bossuet","group":8}, {"name":"Joly","group":8}, {"name":"Grantaire","group":8}, {"name":"MotherPlutarch","group":9}, {"name":"Gueulemer","group":4}, {"name":"Babet","group":4}, {"name":"Claquesous","group":4}, {"name":"Montparnasse","group":4}, {"name":"Toussaint","group":5}, {"name":"Child1","group":10}, {"name":"Child2","group":10}, {"name":"Brujon","group":4}, {"name":"Mme.Hucheloup","group":8}]; d3.select("body").selectAll("p") .data(dataset) .enter() .append("p") .text("New paragraph!") </script> </body> </html>
Yes, I did. I think Javascript cannot locate "miserable.json" nor access the nodes in it. I say this because I have assigned the content of "miserables.json" to an object defined into "index.html" without success. Then, I created an array of nodes(without identifying them as being node), pasted the code for the array into the "index.html" file, and wrote a for loop printing as many "hello wolrd" as there are objects in the array; at first, the browser said that d3 was not defined, then it worked when I referenced the url of the online d3 library instead of the d3 folder on my computer.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>D3 Test</title> <script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> </head> <body> <script type="text/javascript"> var dataset = [{"name":"Myriel","group":1}, {"name":"Napoleon","group":1}, {"name":"Mlle.Baptistine","group":1}, {"name":"Mme.Magloire","group":1}, {"name":"CountessdeLo","group":1}, {"name":"Geborand","group":1}, {"name":"Champtercier","group":1}, {"name":"Cravatte","group":1}, {"name":"Count","group":1}, {"name":"OldMan","group":1}, {"name":"Labarre","group":2}, {"name":"Valjean","group":2}, {"name":"Marguerite","group":3}, {"name":"Mme.deR","group":2}, {"name":"Isabeau","group":2}, {"name":"Gervais","group":2}, {"name":"Tholomyes","group":3}, {"name":"Listolier","group":3}, {"name":"Fameuil","group":3}, {"name":"Blacheville","group":3}, {"name":"Favourite","group":3}, {"name":"Dahlia","group":3}, {"name":"Zephine","group":3}, {"name":"Fantine","group":3}, {"name":"Mme.Thenardier","group":4}, {"name":"Thenardier","group":4}, {"name":"Cosette","group":5}, {"name":"Javert","group":4}, {"name":"Fauchelevent","group":0}, {"name":"Bamatabois","group":2}, {"name":"Perpetue","group":3}, {"name":"Simplice","group":2}, {"name":"Scaufflaire","group":2}, {"name":"Woman1","group":2}, {"name":"Judge","group":2}, {"name":"Champmathieu","group":2}, {"name":"Brevet","group":2}, {"name":"Chenildieu","group":2}, {"name":"Cochepaille","group":2}, {"name":"Pontmercy","group":4}, {"name":"Boulatruelle","group":6}, {"name":"Eponine","group":4}, {"name":"Anzelma","group":4}, {"name":"Woman2","group":5}, {"name":"MotherInnocent","group":0}, {"name":"Gribier","group":0}, {"name":"Jondrette","group":7}, {"name":"Mme.Burgon","group":7}, {"name":"Gavroche","group":8}, {"name":"Gillenormand","group":5}, {"name":"Magnon","group":5}, {"name":"Mlle.Gillenormand","group":5}, {"name":"Mme.Pontmercy","group":5}, {"name":"Mlle.Vaubois","group":5}, {"name":"Lt.Gillenormand","group":5}, {"name":"Marius","group":8}, {"name":"BaronessT","group":5}, {"name":"Mabeuf","group":8}, {"name":"Enjolras","group":8}, {"name":"Combeferre","group":8}, {"name":"Prouvaire","group":8}, {"name":"Feuilly","group":8}, {"name":"Courfeyrac","group":8}, {"name":"Bahorel","group":8}, {"name":"Bossuet","group":8}, {"name":"Joly","group":8}, {"name":"Grantaire","group":8}, {"name":"MotherPlutarch","group":9}, {"name":"Gueulemer","group":4}, {"name":"Babet","group":4}, {"name":"Claquesous","group":4}, {"name":"Montparnasse","group":4}, {"name":"Toussaint","group":5}, {"name":"Child1","group":10}, {"name":"Child2","group":10}, {"name":"Brujon","group":4}, {"name":"Mme.Hucheloup","group":8}]; d3.select("body").selectAll("p") .data(dataset) .enter() .append("p") .text("New paragraph!") </script> </body> </html>
相关问答
更多-
错误在这里: hasLetter("a",words[]); 你传递的是第一个words ,而不是数组。 相反,将数组传递给函数: hasLetter("a",words); 问题解决了! 以下是问题的细目: 我猜你在浏览器中(chrome抛出一个不同的错误), words[] == words[0] ,所以当你调用hasLetter("a",words[]); ,你实际上调用了hasLetter("a",words[0]); 。 所以,实质上,你将第一个单词传递给你的函数, 而不是整个数组。 当然,因 ...
-
Uncaught TypeError:无法读取未定义的属性'onDismiss'(Uncaught TypeError: Cannot read property 'onDismiss' of undefined)[2022-05-11]
您正在使用this.state.list.map(function(item) { ... }) ,因此您的上下文是map函数的上下文。 如果将其更改为this.state.list.map(item => { ... }) ,它将起作用。 这是因为箭头函数会自动绑定this范围的父项。 并且在你的map函数中没有onDismiss函数。 当你在构造函数中绑定this时, onDismiss函数将接收你的组件上下文。 但是,您仍然必须传递组件功能,在这种情况下,您不会这样做。 You are using t ... -
我认为你正在失去这个背景。 你可以像这样格式化你的代码。 import React, { Component } from 'react'; import client from './Credentials'; import '../App.css'; import DisplayResult from './DisplayResult'; export default class Search extends Component { constructor(props) { s ...
-
事实证明,当我移动到新表单时,我忘记了表单周围的ID。 一旦我更换它,错误就会消失并自动完成。 It turns out when I moved to the new form I forgot an ID that surrounds the form. Once I replace it the errors went away and it auto completes.
-
Uncaught TypeError:无法读取未定义的属性'open'(Uncaught TypeError: Cannot read property 'open' of undefined)[2023-08-11]
在构造函数中,你调用this.find(); 在分配给this.port ,因此在内部的this.port行find错误。 改变它以便在填充port属性后运行this.find 。 function Sensors(com) { this.address = com; this.port = new sp(com, { baudrate: 9600, autoOpen: false }); this.find(); } In the constructor, you're ... -
data.docs未定义。 根据你的JSON结构,你正在寻找data.response.docs 。 data.docs is undefined. Per your JSON structure, you're looking for data.response.docs.
-
Uncaught TypeError:无法读取未定义的属性'rank'(Uncaught TypeError: Cannot read property 'rank' of undefined)[2023-10-05]
您必须将函数引用传递给addEventListener (一个使用正确参数调用flipCard的函数)。 那么你会遇到这样的问题 ,你可以这样解决: var createBoard = function() { for (var i = 0; i < cards.length; i ++) { var cardElement = document.createElement('img'); cardElement.setAttribute("img", "images ... -
d3.js - 未捕获的TypeError:无法读取未定义的属性“数据”(d3.js - Uncaught TypeError: Cannot read property 'data' of undefined)[2023-01-26]
对于我的问题,结果证明与d3.v3不兼容。 我使用的是d3.v3,但是nvd3的稳定版本使用d3.v2: https : //github.com/novus/nvd3/commit/7e9b8c013c4d8e8ad5775062c438c842bc112585 我通过包含nvd3 / lib中提供的d3.v2版本解决了这个问题: https : //github.com/novus/nvd3/blob/master/lib/d3.v2.min.js 在这里找到答案: https : //stackove ... -
是的,我做到了。 我认为Javascript无法找到“miserable.json”,也无法访问其中的节点。 我这样说是因为我已经将“miserables.json”的内容分配给定义为“index.html”的对象而没有成功。 然后,我创建了一个节点数组(没有将它们标识为节点),将数组的代码粘贴到“index.html”文件中,并编写了一个for循环打印尽可能多的“hello wolrd”,因为阵列; 起初,浏览器说d3没有定义,然后当我引用在线d3库的url而不是我的计算机上的d3文件夹时,它工作了。 ...
-
问题是this.canvas没有指向对象的canvas属性,它指向全局对象window 。 您需要不同地初始化canvas_width ,例如在init函数中。 与context相同: var Ship = function () { return { canvas: $('#area')[0], ship_image: new Image(), ship_width: null, ship_height: null, ...