{"id":2467,"date":"2019-04-08T09:08:21","date_gmt":"2019-04-08T09:08:21","guid":{"rendered":"http:\/\/www.bardecode.com\/newsite\/?p=2467"},"modified":"2019-04-08T09:17:02","modified_gmt":"2019-04-08T09:17:02","slug":"reading-binary-data-barcode-using-visual-c","status":"publish","type":"post","link":"https:\/\/www.bardecode.com\/newsite\/reading-binary-data-barcode-using-visual-c\/","title":{"rendered":"Reading binary data from a barcode using Visual C#"},"content":{"rendered":"<p>If you are handling binary data in barcodes such as you find in some 2-D barcodes (PDF417, QrCode or DataMatrix) then the following method will allow you to create a byte array that contains the original binary data from the barcode &#8211; including all the null and 8-bit values.<\/p>\n<p>1. Using Quoted printable Encoding<\/p>\n<p>barcode.Encoding = 1;<\/p>\n<p>This will return the barcode value using either printable characters or =XX where XX is a hex value for non-printable characters (e.g for null you get =00). By default the data will be potentially be handled as if it contains utf-8 encoded data.<\/p>\n<p>2. Convert the quoted printable output from GetBarString to a byte array using the following function:<\/p>\n<p>[code]<br \/>\n        private byte[] convertQPToByteArray(string qpString)<br \/>\n        {<br \/>\n            \/\/ Assess how many bytes required<\/p>\n<p>            int c = 0;<\/p>\n<p>            for (int i = 0; i < qpString.Length; i++, c++)\n                if (qpString[i] == '=')\n                    i += 2;\n\n            byte[] binaryData = new byte[c];\n\n            int zero = Convert.ToInt16('0');\n\n            c = 0;\n            for (int i = 0; i < qpString.Length; i++, c++)\n            {\n                if (qpString[i] == '=')\n                {\n                    binaryData[c] = (byte) int.Parse(qpString.Substring(i + 1, 2), System.Globalization.NumberStyles.HexNumber);\n                    i += 2;\n                }\n                else\n                {\n                    binaryData[c] = Convert.ToByte(qpString[i]);\n                }\n             }\n\n            return binaryData;\n        }\n[\/code]\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are handling binary data in barcodes such as you find in some 2-D barcodes (PDF417, QrCode or DataMatrix) then the following method will allow you to create a byte array that contains the original binary data from the barcode &#8211; including all the null and 8-bit values. 1. Using Quoted printable Encoding barcode.Encoding &hellip; <\/p>\n","protected":false},"author":1,"featured_media":538,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[236,18,31],"tags":[],"class_list":["post-2467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-documentation-for-our-toolkits-and-applications","category-knowledge-base","category-software-development-kits"],"_links":{"self":[{"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/posts\/2467"}],"collection":[{"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/comments?post=2467"}],"version-history":[{"count":7,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/posts\/2467\/revisions"}],"predecessor-version":[{"id":2474,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/posts\/2467\/revisions\/2474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/media\/538"}],"wp:attachment":[{"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/media?parent=2467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/categories?post=2467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bardecode.com\/newsite\/wp-json\/wp\/v2\/tags?post=2467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}