473,396 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help me understand this code plz

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.  
  4.  
  5. char *HexToBin[16] =
  6.  
  7. { "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
  8.  
  9.   "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
  10.  
  11. };
  12.  
  13. //---------------------------------------------------------------------------
  14.  
  15. #define UCHAR unsigned char
  16.  
  17.  
  18.  
  19. void print_bits(char *text, void *mem, unsigned char len)
  20.  
  21. { unsigned char *addr;
  22.  
  23.   unsigned char i;
  24.  
  25.   unsigned int l;
  26.  
  27.  
  28.  
  29.   // *** Print Binary Value of Memory *** //
  30.  
  31.   printf(text);
  32.  
  33.   l = 0;
  34.  
  35.   for (addr=(UCHAR *)mem + len - 1; addr>=(UCHAR *)mem; addr--)
  36.  
  37.   {  printf("%4s", &HexToBin[*addr>>4][0]);
  38.  
  39.      printf("%4s ", &HexToBin[*addr % 16][0]);
  40.  
  41.      l <<= 8;
  42.  
  43.      l |= *addr;
  44.  
  45.   }
  46.  
  47.   printf("\n");
  48.  
  49. }
  50.  
  51. //---------------------------------------------------------------------------
  52.  
  53. char c;
  54.  
  55. unsigned char uc; 
  56.  
  57. //---------------------------------------------------------------------------   
  58.  
  59. void print_c(void)
  60.  
  61. {  printf("c = %c = %d = 0x%X", c, c, c);
  62.  
  63.    print_bits(" = ",&c, sizeof(c));
  64.  
  65.    printf("\n");  
  66.  
  67. }
  68.  
  69. //---------------------------------------------------------------------------
  70.  
  71. int main(void)
  72.  
  73. {    
  74.  
  75.    c = 65;  print_c();   
  76.  
  77.  
  78.  
  79.    for (c=7; c<=13; c++) print_c(); 
  80.  
  81.  
  82.  
  83.    c = '6';  print_c();
  84.  
  85.  
  86.  
  87.    c = '\'';  print_c();
  88.  
  89.  
  90.  
  91.    c = '\\';  print_c();
  92.  
  93.  
  94.  
  95.    uc = 200;  print_c();
  96.  
  97.  
  98.  
  99.    c = 200; print_c();
  100.  
  101.  
  102.  
  103.    getchar();
  104.  
  105. }
  106.  
specifically the
the value of addressed is shifted four, that will give index for hextobin and then the value of address will be moduled by 16 to give another index for hex values. I am not seeing it.

Expand|Select|Wrap|Line Numbers
  1.  for (addr=(UCHAR *)mem + len - 1; addr>=(UCHAR *)mem; addr--)
  2.  
  3.   {  printf("%4s", &HexToBin[*addr>>4][0]);
  4.  
  5.      printf("%4s ", &HexToBin[*addr % 16][0]);
  6.  
  7.      l <<= 8;
  8.  
  9.      l |= *addr;
  10.  
  11.   }
Oct 31 '07 #1
2 1089
weaknessforcats
9,208 Expert Mod 8TB
What is this code supposed to do?

It's very messy and and the logic is convoluted and there are no comments to help anyone understand what is going on.

Perhaps you could provide more information about this code. I haven't got time to unravel it.
Oct 31 '07 #2
GGnOrE
8
I figured it out though, because my teacher showed me what it was supposed to do. It shows how differant things in c can be represent multiple ways. I was just trying to understand his algorithm and how he went about doing it. I got the values mixed it.but if you copy and paste it and run it, what the code is supposed to do is fairly straight forward.
Oct 31 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: HLong | last post by:
I am trying to understand an example where the Least Significant Bit is replaced. The code is in C# and I am having problems with a line that reads: B= (byte) (Value == 1 ? B | (1 << poss) : B & ~...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
6
by: Astroman | last post by:
Hi guys and girls. This is my first time posting here so go easy :) . I was wondering if someone could please interpret how this csum() function works in the following C code. I know that the...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
3
by: DM | last post by:
newbie trying to set up a Database and keep getting the same result. ERROR An error occured while retrieving the information from the database: Unable to cast COM object of type...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
7
by: Mickyd1561 | last post by:
Hey everyone I'm new to this groups thing and thought maybe someone can help me. My problem is that I can't view specific images on only one website. www.baseballu.net is my baseball team's...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
19
by: mohammaditraders | last post by:
a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions Cal_percentage() which calculate the...
7
by: sara | last post by:
I have a friend doing some pro-bono work for a non-profit that does job training for distressed kids under DCSS care. He asked me for code to do the following (he's using A2003). I can't find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.