{"id":37283,"date":"2004-11-17T07:00:00","date_gmt":"2004-11-17T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/11\/17\/how-do-i-break-an-integer-into-its-component-bytes\/"},"modified":"2004-11-17T07:00:00","modified_gmt":"2004-11-17T07:00:00","slug":"how-do-i-break-an-integer-into-its-component-bytes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20041117-00\/?p=37283","title":{"rendered":"How do I break an integer into its component bytes?"},"content":{"rendered":"<p><P>\nWarning: .NET content ahead.\nFor some reason, this gets asked a lot.\n<\/P>\n<P>\nTo break an integer into its component bytes, you can use\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/cpref\/html\/frlrfSystemBitConverterClassGetBytesTopic.asp\">\nthe BitConverter.GetBytes method<\/A>:\n<\/P>\n<PRE>\nint i = 123456;\nbyte[] bytes = BitConverter.GetBytes(i);\n<\/PRE>\n<P>\nAfter this code fragment, the byte array contains\n<CODE>{&nbsp;0x40, 0xE2, 0x01, 0x00&nbsp;}<\/CODE>.\n<\/P>\n<P>\n<STRONG>Update<\/STRONG> 11am:\nThe endian-ness of the result is determined by\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/cpref\/html\/frlrfsystembitconverterclassislittleendiantopic.asp\">\nthe\n<CODE>BitConverter.IsLittleEndian<\/CODE> property<\/A>.\nThanks to reader Sean McVey for pointing this out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Warning: .NET content ahead. For some reason, this gets asked a lot. To break an integer into its component bytes, you can use the BitConverter.GetBytes method: int i = 123456; byte[] bytes = BitConverter.GetBytes(i); After this code fragment, the byte array contains {&nbsp;0x40, 0xE2, 0x01, 0x00&nbsp;}. Update 11am: The endian-ness of the result is determined [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-37283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Warning: .NET content ahead. For some reason, this gets asked a lot. To break an integer into its component bytes, you can use the BitConverter.GetBytes method: int i = 123456; byte[] bytes = BitConverter.GetBytes(i); After this code fragment, the byte array contains {&nbsp;0x40, 0xE2, 0x01, 0x00&nbsp;}. Update 11am: The endian-ness of the result is determined [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=37283"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37283\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=37283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=37283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=37283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}